Data Sources & Adapters
Register a source
registerSource
pairs an in-memory value with a name. It does not copy or convert anything; it
is a constant-time operation, so you can register large structures freely.
db.registerSource(['users'], usersArray);
db.registerSource(['crm', 'invoices'], invoicesArray); // namespaced name
db.registerSource(['social'], graph);
The name is an array of parts, which lets you namespace sources; a query then
refers to the source by the dotted path, for example crm.invoices.
Anything can be registered: an array, an object, a DOM document, or a graph. The language's data adapter decides how to read it.
Choose an adapter
An adapter is the bridge between a language and the concrete shape of your data. Each provided language ships with a default:
| Language | Default adapter | Expects |
|---|---|---|
| SQL | ObjectDataAdapter | array of objects; property = column |
| Cypher | GraphologyDataAdapter | a Graphology graph |
| XQuery | DomDataAdapter | a DOM document / XML tree |
Pass a different one in the language's config when your data has another shape:
mainLang: SQL({ adapter: myAdapter });
SQL
By default SQL treats each element of a registered array as a row and each property as a column. See SQL Overview.
Cypher
The default Graphology adapter expects node labels and edge types under
the
gaLabelsOrType
symbol key. See Cypher Overview. A plain labels
property is not recognized, and label patterns then match nothing.
XQuery
DomDataAdapter
targets DOM/XML. In the browser the global document is used automatically; in
Node you pass a document from a DOM implementation such as
jsdom:
mainLang: XQuery({ adapter: new DomDataAdapter(doc) });
Read a shape no adapter covers
Adapters are a first-class extension point: writing one is how you point a
language at Map-backed rows, a different graph library, or a tree that is not
a DOM. See Data Adapters.