A DatabaseManager holds several named databases, each with its own storage. Clients
use it through a Session, which has a current database and runs the database commands:
CREATE DATABASE movies; // default storage of the manager
CREATE DATABASE scratch IF NOT EXISTS OPTIONS {storage: 'memory'};
CREATE OR REPLACE DATABASE events
OPTIONS {storage: 'hybrid', sync: 'os', checkpointAfterBytes: 16777216};
SHOW DATABASES; // name, storage, default, current, nodes, relationships
SHOW DATABASE movies;
SHOW DEFAULT DATABASE;
USE movies; // switch the session's current database
USE scratch MATCH (n) RETURN count(n); // run one query elsewhere, without switching
DROP DATABASE scratch IF EXISTS;
use graphbuff::DatabaseManager;
let mgr = DatabaseManager::open("data")?; // or DatabaseManager::in_memory()
let mut s = mgr.session(); // starts on the default database, `graphbuff`
s.execute("CREATE OR REPLACE DATABASE movies")?;
s.execute("USE movies")?;
s.execute("CREATE (:Movie {title: 'Heat'})")?;
CREATE OR REPLACE DATABASEdrops an existing database with all its data and creates it again empty, with the given options; if it doesn't exist it is just created. It cannot be combined withIF NOT EXISTS. PlainCREATE DATABASEfails if the name is taken;IF NOT EXISTSleaves the existing database alone.- Options:
storageis'memory','hybrid'or'persistent'.sync('commit'or'os') andcheckpointAfterBytesapply to hybrid and persistent storage,cacheBytesandmaxTransactionBytes(the transaction size cap) to persistent storage. WithoutOPTIONS, a manager opened on a directory creates hybrid databases (persistent ones with--persistentin the shell, orDatabaseManager::open_with(dir, StorageKind::persistent())) and an in-memory manager creates memory databases.OPTIONS $mapworks too, as does$namefor the database name.WAIT/NOWAITandDESTROY DATAare accepted and ignored. - Names are case-insensitive, 1–63 characters (letters, digits,
.,-,_), start with a letter, and need backticks if they contain-. Windows device names such asconare rejected because names are also folder names. - The default database (
graphbuff) cannot be dropped, but it can be replaced. Dropping a session's current database moves that session back to the default one. - On disk,
data/cataloglists the databases and their storage settings, and each hybrid or persistent database lives indata/databases/<name>/. Memory databases stay in the catalog across restarts but come back empty. ALOCKfile keeps a second process out. - A plain
Databasehas no other databases, so it rejectsUSEand database commands with anUnsupportederror.
In the shell, :use name and :dbs are shortcuts, and the prompt shows the current
database.
Try it on your machine: one command starts the server with the movies graph. Needs Docker.
$ docker run --rm -p 127.0.0.1:7475:7475 -p 127.0.0.1:7687:7687 ghcr.io/janvencl/graphbuff --demo moviesThen follow Getting started.