Discussion Forum

Defining schema with java api; grakn 2.0

New to grakn, Jumping right in with 2.0. Looking for examples of defining schema in the java api.



Here you go, check this out!

you’ll probably want to include the Graql repository to parse the schema into a Graql define query

In fact, you can see how our Graql console that is bundled with Grakn server does this right here:

hope that helps!

That helped. also new to graql queries. is there one that will list out the schema for a database? Tried this:

transaction idml schema read
idml::schema::read> match $p isa thing; get $p;

answers: 0, duration: 42 ms
idml::schema::read> match $p isa entity; get $p;

answers: 0, duration: 32 ms

This was my attempt to define an entity:

// add the schema
val schema_session = client.session(DBNAME, GraknClient.Session.Type.SCHEMA)
val wrtr = schema_session.transaction(Transaction.Type.WRITE)
val ql = Graql.parseDefinables("Identity sub entity;")
val q = new GraqlDefine(ql)

never mind! found an example elsewhere.

You can list out all types in the database with match $t sub thing; (note sub not isa)

there’s also a feature on the server ./grakn server schema [database name] (http://dev.docs.grakn.ai/docs/management/migration-and-backup)