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
recordsare passed to and from the database via protobuf messagesrecordsare added and retrieved using akey, which is therecord'saliasfield.- to keep track of projects locally,
starkhas 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 arecordto an open database.stark get <key>- Get arecordfrom 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
projectis found it will recover the most recentsnapshot CIDfor thisprojectand then collect all therecordlinks in a key-value store - if the
projectis not found,starkwill 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
addandgetin another
Flags
--withListen
- tells the database to listen for
recordsbeing 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
projectname, my database instance could pull in allrecordsthat my collaborator was adding to their database (provided they were using the--withAnnounceflag) - this works best if
--withPeersis used to connect the two databases directly
--withAnnounce
- this is used to announce
recordsas they are added to the database - announced
recordscan be picked up by databases that are listening (via the--withListenflag)
--withEncrypt
- encrypts
recordfields when adding arecordto the database - this flag must also be used to get encrypted
records - if you try to
getan encryptedrecordwithout this flag, thegetwill fail - to provide the encryption password, use the
STARK_DB_PASSWORDenvironment variable
--withPinata <int>
--withPeers <string>
Add
To add a record to an open database:
cat record.json | stark add
- the
recordmust follow the schema or theaddwill fail - the
recordalias is used as the databasekey, which is needed forrecordretrieval - if no STDIN or file is provided, the
addsubcommand will collect therecordinteractively using a user prompt (this is a WIP)
Flags
--useProto
- tells the database that the
recordbeing added is in protobuf format, not JSON
--inputFile <string>
- use this flag to provide the
recordvia 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
recordas human readable text
--useProto
- tells the database return the
recordin protobuf format, not JSON
Dump
To dump the current metadata from an open database:
stark dump