Overview
jQL (Jeli Query Language) is how jDB performs table operations, calls REST APIs registered
with a database, and drives its own environment — all through a single method:
db.jQl(query, params).
db.jQl(query, params) → Promise
| Argument | Type | Required | Notes |
query | string | object | array | Yes | A single command (string or object), or an array of them to run in sequence. |
params | object | No | Values substituted into %key% placeholders inside a string query. |
Every command — insert, select, drop, and so on
— is a plugin registered with its own schema: a declared set of
fields with names, optional types, defaults and flags. The schema is what makes both syntaxes
below, and the object form, resolve to exactly the same thing.
Deprecated: db.jQl(query, handler, params) (a second
{onSuccess, onError} argument) still works but logs a deprecation warning.
Use the returned Promise instead.
Two syntaxes, one schema
jDB detects which syntax a string query uses automatically — nothing to configure, and
the two can be mixed freely across calls.
v1 Positional flags
The original syntax: a command name followed by -value tokens. Non-flag fields
are matched by position; boolean fields are matched by typing their
name as a bare word anywhere in the query.
insert -{"name":"Ada","role":"admin"} -users -ignoreSync -hard
v2 Named flags
A newer --name=value / bare --name syntax. Fields are matched by
name instead of position, so flags can appear in any order. jDB only treats
-- as a flag boundary outside quotes/braces and immediately before a letter, so
JSON data containing a dash ({"score": -5}) is never misread — that
exact ambiguity is why v1 requires care with values containing -.
insert --data={"name":"Ada","role":"admin"} --table=users --ignoreSync --hard
Object form
Skip string parsing entirely by handing jQl a plain object with a
command key. This is the most robust option for code generating queries
programmatically.
db.jQl({
command: 'insert',
table: 'users',
data: { name: 'Ada', role: 'admin' },
ignoreSync: true
});
Field types
Each command's fields table below lists a type badge where the command validates that field.
A field with no badge accepts anything it's given (its shape legitimately varies —
e.g. insert's data is an object for a single record or an array
for a bulk insert).
| Badge | Meaning |
| string | Taken literally, never coerced — a table named "123" stays the string "123", not the number 123. |
| boolean | Must resolve to true/false; anything else is rejected with a clear error. |
| number | Must resolve to a number. |
| object | Must resolve to a plain object. |
| array | Must resolve to an array. |
| flag | A boolean toggle: typing its name (v1) or --name (v2) sets it true; leaving it out resolves to false. Never a mismatch error — there's no value to validate. |
A type mismatch (e.g. passing "nope" where a command expects an object)
rejects the query with a message naming the field and the expected type, before the
command ever runs.
Response shape
On success, most commands resolve with:
{ state: "insert", status: "success", result: { message: "..." }, code: 200 }
On failure, the promise rejects with:
{ message: "...", status: "error", code: 400 }
select resolves with a result set object exposing getResult() and
jDBNumRows() instead of a plain message.
Table
create
create -table -columns
| Field | Position | Type | Notes |
table | 1 | string | Table name. |
columns | 2 | array | Optional — array of column definitions. Omitted defaults to []. |
create -users -[{"id":{"type":"NUMBER","AUTO_INCREMENT":1},"email":{"type":"VARCHAR"}}]
alter v1 only
alter -table -action -...args
| Field | Position | Type | Notes |
table | 1 | string | |
action | 2 | string | a add, d drop, r rename, u update mode. |
...args | 3+ | | Meaning depends on action — see below. |
When action is a (add), the next argument selects what's being
added:
| Sub-action | Adds | Remaining args |
c | column | column name, config object |
p | primary key | column name |
f | foreign key | column name, relative table |
i | index | config object |
m | read/write mode | mode |
alter -users -a -c -fullName -{"type":"VARCHAR","defaultValue":"Foo Bar"}
alter -users -d -fullName
alter -users -r -people
v2 (--name=value) syntax isn't supported for alter yet.
Its trailing arguments are positional by meaning (sub-action, then column, then config), and
named syntax has no positional-order concept to map them from. Use v1 or the object form
for alter until it gets its own named fields (e.g. --subAction=c).
truncate
truncate -table -flag
| Field | Position | Type | Notes |
table | 1 | string | |
flag | 2 | | "yes"/"no" or a boolean — must be truthy to actually run. |
truncate -users -yes
truncate-db
truncate-db -dropFromServer
| Field | Position | Type | Notes |
dropFromServer | 1 | boolean | Optional. |
Truncates every table in the current database.
drop
drop -type -name -flag -localOnly
| Field | Position | Type | Notes |
type | 1 | string | t table, d database. |
name | 2 | string | Table or database name. |
flag | 3 | | "yes"/"no" or a boolean — must be truthy to actually run. |
localOnly | 4 | boolean | Database drops only. |
drop -t -users -yes
drop -d -myapp -yes -true
Transactions
insert
insert -data -table
| Field | Position | Type | Notes |
data | 1 | | Object for a single record, or an array of objects for a bulk insert. |
table | 2 | string | |
replace | — | flag | Upsert by the table's primary key instead of a plain insert. |
hard | — | flag | |
skip | — | flag | Skip data processing/validation. |
ignoreSync | — | flag | |
rollbackOnError | — | flag | |
insert -[{"name":"Foo Bar","email":"foo@bar.com"},{"name":"Bar Foo","email":"bar@foo.com"}] -users
update
update -table -data -cond
| Field | Position | Type | Notes |
table | 1 | string | |
data | 2 | object | Fields to set. |
cond | 3 | | Condition expression. Omit to update every row. |
ignoreSync | — | flag | |
rollbackOnError | — | flag | |
update -users -{"role":"admin"} -age>18
updatemany
updatemany -table -data
| Field | Position | Type | Notes |
table | 1 | string | |
data | 2 | array | Array of [cond, data] pairs, one update per pair. |
updatemany -users -[[{"age":18},{"role":"admin"}]]
delete
delete -table -cond -ignoreSync
| Field | Position | Type | Notes |
table | 1 | string | |
cond | 2 | | Condition expression. Omit to delete every row. |
ignoreSync | 3 | boolean | Positional, not a bare flag, on this command. |
rollbackOnError | — | flag | |
delete -users -age>18 -true -rollbackOnError
select
select -fields -table -...clauses
| Field | Position | Type | Notes |
fields | 1 | string | *, a comma-separated list, or col as alias. |
table | 2 | string | Comma-separated for multiple tables (e.g. joins). |
...clauses | 3+ | | join(...), where(...), limit(...), orderBy(...), groupBy(...) — any number, any order. |
Condition operators inside where(...):
| Operator | Meaning |
=== | is |
== / = | equals |
>= > <= < | comparison |
!= | not equal |
!== | is not |
~ | like |
[] / ![] | in array / not in array |
[=] / [!] | in clause / not in clause (subquery) |
v1
select -* -users -where(role~admin) -limit(10) -orderBy(name)
v2
select --fields=* --table=users --where=role~admin --limit=10
Unlike alter, select's clauses are supported under v2:
any --name=value not matching fields/table is
collected as a clause of that name, so --where=... and
--limit=... work exactly like their v1 -where(...) /
-limit(...) equivalents.
Join clause: join(@table(t2) @clause(INNER) @on(t1.column=t2.column)), with
INNER, LEFT, RIGHT or OUTER. All
referenced tables must already exist.
batch
batch -transactions
| Field | Position | Type | Notes |
transactions | 1 | array | Array of {type, table, data, query, hardInsert} transaction descriptors. |
rollbackOnError | — | flag | Roll back the whole batch if any transaction fails. |
batch -[{"type":"insert","table":"users","data":{"name":"Ada"}}] -rollbackOnError
Data
import
import -table -fileType -isSchema
| Field | Position | Type | Notes |
table | 1 | string | |
fileType | 2 | string | json, jql, csv or html. |
isSchema | 3 | boolean | |
Opens a file picker. If the table doesn't exist yet, it's created before the data is
inserted.
export
export -table -type -action -fileName -title
| Field | Position | Type | Default |
table | 1 | string | all |
type | 2 | string | json (also csv, html, jql) |
action | 3 | string | print (d to download) |
fileName | 4 | string | "" |
title | 5 | string | "" |
export -users -csv -d -users-export
sync
sync -table -force -syncData
| Field | Position | Type | Notes |
table | 1 | string | Omit to sync every table. |
force | 2 | boolean | |
syncData | 3 | | |
sync -users -true
Environment
schema
schema -action -arg
| Field | Position | Type | Notes |
action | 1 | string | export or add. |
arg | 2 | | Server flag for export; schema data for add. |
schema -export -true
schema -add -{"users":{"type":"create","definition":[{"id":{"type":"NUMBER"}}]}}
env
env -method -arg
| Field | Position | Type | Notes |
method | 1 | string | logger, resource or usage. |
arg | 2 | | Passed straight to the chosen method. |
env -usage
help
help -target
| Field | Position | Type | Notes |
target | 1 | string | Optional — a command name to look up. Omit to list every command's help text. |
help
help -insert
api
api -path -data
| Field | Position | Type | Notes |
path | 1 | | A route string, or a full request object ({URL, METHOD, AUTH_TYPE, body}). |
data | 2 | | Optional request body. |
Calls a REST endpoint registered with the database through the same jQL pipeline as table
commands.
api -/set/access/token -{"token":"abc"}
cls
cls
No fields. Signals a command-line/REPL front end (like the playground) to clear its output.
Doesn't touch the database.