A very quick tutorial combining the individual elements of the JavaScript how-to guides to get you started.
This guide demonstrates the basic use of the WOQLClient library to connect to TerminusDB with the JavaScript Client. Refer to TerminusDB JavaScript Client Reference Guide for detailed documentation.
The code discussed on this page is also available in full on GitHub - getting-started.js
You can also find a comprehensive getting-started guide on GitHub: 5-Part JS Client Getting Started Guide.
Common uses of a WOQLClient include connecting to an existing database and creating a new database.
Connect to an existing database using the example below.
Create a new database using the example below.
Create a schema and add documents to the schema by using the document interface. Refer to the Document Interface Reference Guide for more detail. After creating or connecting to a database, create a schema to add and retrieve data. A simple player roster is used as an example. Using Player roster data, the steps below are demonstrated.
Create a schema
Add a schema
Add documents
Get documents
Query documents
Data: Player roster
Code: Create a schema
Create a schema object with properties name
and position
. The object is uniquely identified by name
.
Code: Add a schema
Add the schema object to the database.
Add the schema object to a document using addDocument
which returns a Promise.
Code: Add documents
Once a schema is added, add documents corresponding to the schema.
Add documents to the schema using addDocument
which returns a Promise.
Code: Get documents
Get a list of documents or specific documents added to the schema
Get a list of documents using getDocument
as_list
. Results, stored in document
, are shown further below.
Code: Query documents
Get a list of documents that matches the query
Get a list of documents using getDocument
as_list
. Results, stored in document
, are shown further below.
Code: Query documents using WOQL
Query documents using Web Object Query Language (WOQL) to get the same result given by the above example. You can find more about WOQL here.
Get documents using using WOQL.triple()
to create a WOQL query then execute that query using client.query()
. Results, stored in results
, are shown further below
The following code segments demonstrate creating relationships or links between documents
Code: Create schema for team
The Team
object is uniquely identified by the property name
. The players
property consists of a set of Player
classes that create a link between theTeam
and Player
schema.
Code: Add a schema
Add the schema object to the database.
Add the schema object to a document using addDocument
that returns a Promise.
Code: Add documents
Add documents corresponding to the Team
schema.
Code: Get all of the teams
Get a list of Team
documents.