Using stark as an app
Overview
The app is used to manage stark databases. Here are a few key points:
- a database must be open in order to run
add
/get
/dump
- one database can be open at a time
- an open database is interfaced by a gRPC server
records
are passed to and from the database via protobuf messagesrecords
are added and retrieved using akey
, which is therecord's
alias
field.- to keep track of projects locally,
stark
has a config file which stores the most recent databasesnapshot
(default location:~/.stark.json
)
Subcommands
stark open <project>
- Open a database for aproject
.stark add
- Add arecord
to an open database.stark get <key>
- Get arecord
from an open database.stark dump
- Dump the current metadata from an open database.
Open
To open a database, just use the open
subcommand:
stark open my-project
This will check the stark config file and see if a database has been opened for this project
before:
- if the
project
is found it will recover the most recentsnapshot CID
for thisproject
and then collect all therecord
links in a key-value store - if the
project
is not found,stark
will open a new database and add it to the config for next time - it's easiest to open the database in one terminal window and then run
add
andget
in another
Flags
--withListen
- tells the database to listen for
records
being added to other database instances for the sameproject
- for instance, if I had a database open for metagenomics-project-101 and a collaborator also had a database open with this
project
name, my database instance could pull in allrecords
that my collaborator was adding to their database (provided they were using the--withAnnounce
flag) - this works best if
--withPeers
is used to connect the two databases directly
--withAnnounce
- this is used to announce
records
as they are added to the database - announced
records
can be picked up by databases that are listening (via the--withListen
flag)
--withEncrypt
- encrypts
record
fields when adding arecord
to the database - this flag must also be used to get encrypted
records
- if you try to
get
an encryptedrecord
without this flag, theget
will fail - to provide the encryption password, use the
STARK_DB_PASSWORD
environment variable
--withPinata <int>
--withPeers <string>
Add
To add a record
to an open database:
cat record.json | stark add
- the
record
must follow the schema or theadd
will fail - the
record
alias is used as the databasekey
, which is needed forrecord
retrieval - if no STDIN or file is provided, the
add
subcommand will collect therecord
interactively using a user prompt (this is a WIP)
Flags
--useProto
- tells the database that the
record
being added is in protobuf format, not JSON
--inputFile <string>
- use this flag to provide the
record
via file instead of STDIN or interactively
Get
To get a record
from an open database:
stark get <key>
Flags
--humanReadable
- use this flag to print the
record
as human readable text
--useProto
- tells the database return the
record
in protobuf format, not JSON
Dump
To dump the current metadata from an open database:
stark dump