User Guide
Installation
To use this client, you need a compatible TypeDB Server running. You can find install instructions in the TypeDB Documentation.
Compatibility table:
TypeDBClient.jl | TypeDB | TypeDB Cluster | Julia |
---|---|---|---|
0.1.0 | 2.4 | - | >=1.6 |
0.1.1 | 2.5, 2.6 | - | >=1.6 |
Inside the Julia REPL, type ] to enter the Pkg REPL mode then run
pkg> add TypeDBClient
Quickstart
First make sure the TypeDB server is running. See Start the TypeDB Server section.
In the Julia REPL or in your source code:
using TypeDBClient
You have two choices:
- If you are only interested in working interactively, you can use the more simplified API. An example for this is:
using TypeDBClient: dbconnect, open, read, write, match, insert, commit, create_database
# Connecting the client to TypeDB
dbconnect("127.0.0.1") do client
# Create a database
create_database(client, "my-typedb")
# Opening a session
open(client, "my-typedb") do session
# Open a write transaction
write(session) do transaction
# Insert a record using TypeQL
insert(transaction, raw"insert $_ isa person;")
# Commit the transaction
commit(transaction)
end
# Open a read session
read(session) do transaction
# Make a match request with a TypeQL string
answers = match(transaction, raw"match $p isa person;")
end
end
end
For working with data using TypeQL, please refer to the syntax on TypeQL Documentation
- If you want the full stack at your fingertips, then you can use the following commands:
using TypeDBClient
# Only for convenience reasons, you can write the full name if you want
g = TypeDBClient
# Create a client
client = g.CoreClient("127.0.0.1",1729)
# Create a database called typedb if the database wasn't already created by you previously.
g.create_database(client, "typedb")
#=
Open a session to write in the schema section of the database.
Be careful if you work with a schema session. No more sessions are allowed
until you close this session. Closing a session is mandatory. Don't forget this
at the end of your work.
=#
session = g.CoreSession(client, "typedb" , g.Proto.Session_Type.SCHEMA, request_timeout=Inf)
# Open a write transaction
transaction = g.transaction(session, g.Proto.Transaction_Type.WRITE)
#=
Make a query in the database
The result of this query will be a vector of ConceptMap.
From there you can access the data as you want.
=#
results = g.match(transaction, "match \$x sub thing;")
# If you want to work further in the session, go ahead, else close the session.
close(session)
If you want to use the full potential of the client you should read the documentation of the API functions. There you will find all you need for working programmatically in the database. Otherwise, it is even possible to get equal results using TypeQL.
User API
delete
There are some delete functions:
database
delete_database(client::AbstractCoreClient, name::AbstractString)
type
unset_has(transaction::AbstractCoreTransaction, thing::AbstractThing, attribute::Attribute)
Any type can be deleted with this function. Be aware that only types which have no instances in the database can be deleted.
get_instances
get_owns
get_owners
- Attribute
- AttributeType
get_owners(r::RemoteConcept{<: AbstractAttributeType}, only_key = false)
get_regex
get_rule
get_rule(log_mgr::AbstractLogicManager, label::AbstractString)
get_subtypes
get_supertype
get_supertypes
set_abstract
set_has
set_has(transaction::AbstractCoreTransaction, thing::AbstractThing, attribute::Attribute)
set_supertype
unset_abstract