First database
Build the shell, open a .ndbc file, define a schema, insert and query rows.
Build the shell#
NarDB Shell is built from source and needs Go 1.26.
cd nardb_shell
go build -o nardb .
./nardbOn first run you set a password for nardb-root-user. It is hashed with Argon2id, and only the hash is written to the system keychain (macOS Keychain, Windows Credential Manager, Linux Secret Service).
Create a database#
Press Esc to open the menu and choose File → New ▸ Database.... Or press Ctrl+L to go to the command line at the bottom and type:
>> create_local_database -f ./data/shop.ndbcshop.ndbc is created as a folder, encrypted by default with its key in the system keychain (see Encryption). It is never overwritten if it exists. Only one process can open a database at a time. Single-file .ndbc databases from older versions are converted to this layout when opened; the old file is kept with a .v1 suffix.
Define a schema#
create_schema -n members puts a template into the editor. Edit it and press F5 to run it:
create_schema('members')
.fields({
'id': {type: string, max_length: 32, guid: true, primary_key: true},
'name': {type: string, max_length: 50},
'email': {type: string, max_length: 100, index: {unique: true}},
'birth': {type: date, format: 'dd.mm.yyyy'}
})
.commit();Without .commit() the schema is only validated, not created. To try the validation, remove that line and press F5.
Insert and query#
from('members').insert_one({name: 'Osman', email: 'osman@example.com', birth: '23.09.1981'});
from('members').insert_one({name: 'Ayşe 🍉', email: 'ayse@example.com'});
from('members')
.where({'email': 'osman@example.com'})
.fields('name', FORMAT('birth', 'dd-mm-yyyy'))
.get();You did not give an id: because of guid: true the engine generated a 32-character id. birth was stored with the dd.mm.yyyy format; FORMAT showed it in a different one.
Save the query#
Ctrl+S saves the editor as a .nqf file (nardb query file). A .nqf file is plain UTF-8 text and opens in any editor. To open it in the shell again use File → Open Query File... or:
>> open_query -f ./queries/members.nqf