When you close a database in ArcadeDB, it:
The name of the database to close.
The response from the server.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function closeDatabaseExample(databaseName: string) {
try {
const closed = await server.closeDatabase(databaseName);
console.log(closed);
// true
} catch (error) {
// manage error conditions
console.error(error);
}
};
closeDatabaseExample('aDatabase');
Sends a command to the ArcadeDB server and returns the response.
This method provides a way to execute arbitrary commands on the server, such as creating databases, executing queries, or performing administrative tasks.
The command to send to the server, such as CREATE DATABASE aDatabase
. The command string should be a valid ArcadeDB command, and it's case-sensitive.
The response from the server, simplified from the raw JSON response. The response object will contain the result
property, which can be a boolean value (e.g., OK
), a string, or an object. Other properties may include user
, version
, and serverName
.
If the command fails to execute, an error will be thrown with a message describing the problem. The error object will contain a cause
property with the underlying error.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function commandExample(databaseName: string) {
try {
const response = await server.command(`CREATE DATABASE ${databaseName}`);
console.log(response);
// {
// user: 'aUser',
// version: '24.x.x',
// serverName: 'ArcadeDB_0',
// result: 'ok'
// }
} catch (error) {
// Will throw an error for conditions such as:
// Invalid credentials, Database Already Exists, etc.
console.error(error);
// {
// message: 'Encountered an error when sending a command to the server.',
// cause: Error: Invalid credentials
// }
}
}
commandExample('aDatabase');
Connects this server to a cluster with address
.
The address of the cluster to connect (i.e. 192.168.0.1)
The response from the server.
Error
if the cluster could not be connected.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function connectClusterExample(address: string) {
try {
const connected = await server.connectCluster(address);
console.log(connected);
// true
} catch (error) {
console.log(error);
// handle error conditions
}
}
connectClusterExample('192.168.0.1');
Create a database
The name of the database to create.
An instance of SpriteDatabase
, targeting the created database.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function createDatabaseExample(databaseName: string) {
try {
const database = await server.createDatabase(databaseName);
console.log(database.name);
// 'aDatabase'
} catch (error) {
console.log(error);
// handle error conditions
}
}
createDatabaseExample('aDatabase');
Create a user. username
, password
, and access controls to multiple databases
can be established using the databases
property of the input parameters.
The databases
object uses 'groups' to grant access controls. Assigning
a user to groups within a specific database grants them the permissions associated
with those groups for a particular database.
true
if the user was created successfully.
Error
if the user could not be created.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function createUserExample(details: ISpriteCreateArcadeUser) {
try {
const created = await server.createUser(details);
console.log(created);
// true
} catch (error) {
console.error(error);
// handle error conditions
}
}
createUserExample({
username: 'myUsername',
password: 'myPassword',
databases: {
"FirstDatabase": "admin"
"SecondDatabase": "user"
}
});
Returns a SpriteDatabase
instance for the supplied databaseName
,
using the authorization details of the SpriteServer
instance.
The name of the database to create a client for.
An instance of SpriteDatabase
.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function databaseExample() {
try {
const database = await server.database('aDatabase');
// returns an instance of SpriteDatabase
console.log(database.name);
} catch (error) {
// handle errors
console.error(error);
}
};
databaseExample();
Disconnects the server from the cluster.
The response from the server.
Error
if the cluster could not be disconnected.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function disconnectClusterExample() {
try {
const disconnected = await server.disconnectCluster();
console.log(disconnected);
// true
} catch (error) {
console.error(error);
// handle error condition
}
}
disconnectClusterExample();
Drop a database
The name of the database to drop.
true
if successfully dropped.
Error
if the database could not be dropped.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function dropDatabaseExample(databaseName: string) {
try {
const dropped = await server.dropDatabase(databaseName);
console.log(dropped);
// true
} catch (error) {
console.error(error);
// handle error condition
}
}
dropDatabaseExample('aDatabase');
Drop a user from the ArcadeDB server.
The username
of the user to drop from the ArcadeDB server.
true
if the user was successfully dropped.
Error
if the user could not be dropped.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function dropUserExample(username: string) {
try {
const dropped = await server.dropUser(username);
console.log(dropped);
// true
} catch (error) {
console.error(error);
// handle error condition
}
}
dropUserExample('aUser');
Retrieves a list of server events, optionally a filename of the form
server-event-log-yyyymmdd-HHMMSS.INDEX.jsonl
(where INDEX is a integer, i.e. 0)
can be given to retrieve older event logs.
An object containing he server events from the server, and filenames of the associated logs.
Error
if there was a problem fetching the event logs.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function getServerEventsExample() {
try {
const events = await server.getServerEvents();
console.log(events);
// {
// events: [
// {
// "time":"2024-01-30 06:37:20.325",
// "type":"INFO","component":"Server",
// "message":"ArcadeDB Server started in \\u0027development\\u0027 mode (CPUs\\u003d8 MAXRAM\\u003d3.84GB)"}]
// }
// ],
// files: [
// "server-event-log-20240205-060106.13.jsonl",
// "server-event-log-20240204-185020.12.jsonl",
// "server-event-log-20240204-063235.11.jsonl",
// "server-event-log-20240131-205254.10.jsonl",
// "server-event-log-20240130-133802.9.jsonl"
// ]
// }
} catch (error) {
console.error(error);
// handle error condition
}
}
getServerEventsExample();
Returns the current configuration.
Optional
mode: MThe level of informatio detail to return.
basic
returns minimal server informationdefault
returns full server configuration (default value when no parameter is given)cluster
returns the cluster layoutThe response from the server.
Error
if the information could not be retrieved.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function getInformationExample(mode: ArcadeServerInformationLevel) {
try {
const information = await sprite.getInformation(mode);
console.log(information);
// {
// user: 'aUser',
// version: '24.x.x',
// serverName: 'ArcadeDB_0'
// }
} catch (error) {
console.error(error);
// handle error condition
}
}
getInformationExample('basic');
Returns a list of database names that are present on the server.
A list (array) of database names present on the server.
Error
if the database list could not be retrieved.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function listDatabasesExample() {
try {
const list = await sprite.listDatabases();
console.log(list);
// [ 'databaseName' ]
} catch (error) {
console.error(error);
// handle error condition
}
}
listDatabasesExample();
When you "open" a database in ArcadeDB, it means you're creating an instance of the database in memory, allocating resources, and making the database available for operations. Here's what happens when you open a database:
The name of the database to open.
The response from the server.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function openDatabaseExample(databaseName: string) {
try {
const open = await server.openDatabase(databaseName);
console.log(open);
// true
} catch (error) {
// handle errors
console.error(error);
}
};
openDatabaseExample('aDatabase');
Returns a boolean
value indicating if the ArcadeDB server is ready.
Useful for remote monitoring of server readiness.
true
if the server is ready, otherwise false
.
const client = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function serverReadyExample() {
try {
const ready = await client.serverReady();
if (ready) {
console.log(ready);
// true;
}
} catch (error) {
throw new Error(
'An error occurred while running example.',
{ cause: error }
);
}
}
serverReadyExample();
Gracefully shutdown the server.
TODO:
This works, in that it does shutdown the server, but the fetch throws
before it resolves, guessing because the server is shutting down. A CURL, however,
returns an empty 204
response as the documentation indicates.
true
if the server is successfully shutdown.
Error
if there is a problem attempting the shutdown.
const server = new SpriteServer({
username: 'aUser',
password: 'aPassword',
address: 'http://localhost:2480',
});
async function shutdownExample() {
try {
const shutdown = await server.shutdown();
console.log(shutdown);
} catch (error) {
console.error(error);
// handle error condition
}
}
shutdownExample();
Methods for interact with an ArcadeDB server. Manage databases, users, etc.
Param: parameters
Connection details to access the server with.
Example