-
-
Notifications
You must be signed in to change notification settings - Fork 2
Here we talk about the client.query() method in more detail along with other Linked QL APIs that essentially let you programmatically do the same things possible with client.query().
As an example of one of these APIs, a CREATE DATABASE operation...
const savepoint = await client.query('CREATE DATABASE IF NOT EXISTS database_1');could be programmatically achieved as:
const savepoint = await client.createDatabase('database_1', { ifNotExists: true });That said, while the createDatabase() method is associated with the base Client object, the different programmatic query APIs in Linked QL are actually organized into three hierarchical scopes:
-
the top-level scope (represented by the
Clientinterface), featuring methods such as:createDatabase(),alterDatabase(),dropDatabase(),hasDatabase(),describeDatabase() -
the database-level scope (represented by a certain
Databaseinterface), featuring methods such as:createTable(),alterTable(),dropTable(),hasTable(),describeTable() -
the table-level scope (represented by a certain
Tableinterface), featuring methods such as:select(),insert(),upsert(),update(),delete()
Each object provides a way to narrow in to the next; e.g. from the top-level scope to a database scope...
const database_1 = client.database('database_1');and from there to a table scope:
const table_1 = database.table('table_1');These APIs at play would look something like:
// Create database "database_1"
await client.createDatabase('database_1', { ifNotExists: true });// Enter "database_1" and create a table
await client.database('database_1').createTable({
name: 'table_1', columns: [
{ name: 'column_1', type: 'int', identity: true, primaryKey: true },
{ name: 'column_2', type: 'varchar' },
{ name: 'column_3', type: 'varchar' },
]
});// Enter "table_1" and insert data
await client.database('database_1').table('table_1').insert({
column_2: 'Column 2 test content',
column_3: 'Column 3 test content',
});