-
Notifications
You must be signed in to change notification settings - Fork 13
Database
emli edited this page Nov 21, 2017
·
31 revisions
Gorjun uses bolt. Bolt an embedded key/value database for Go. Bucket is table in bolt.
Gorjun database directory is /opt/gorjun/data/db/my.db. If it not exist it will created automatically. Before create directory opt/gorjun.
- MyBucket - store information about all files in Gorjun. Here key - is a file UUID.
- Users - store all users registered in the system. Key is a username, the value is a bucket with multiple GPG-keys.
- SearchIndex - store a search index for fast accessing artifacts. Key - filename, value - bucket with files UUIDs.
- Tokens - store authentication tokens for user sessions. Key - token, value bucket with username and date of creation.
- AuthID - store AuthID(random string) that user should sign to get token. Key - authID, value - username.
- Tags - another search index that is used to group templates by tags. Key - tag, value - template UUIDs
Transactions
db.Update
- read-write transactions
db.View
- read-only transactions
Working with Tokens
- How to get tokens?
b := tx.Bucket(tokens).Bucket([]byte(token))
As you see above tokens is bucket that store token as key, value bucket with username and date of creation. Token is key.
- How to put values?
b.Put([]byte("name"), []byte(name))
b.Put([]byte("date"), now)
- How to get date and username for token?
After assign bucket to
b
, we can get value by keys.
b.Get([]byte("date"))
b.Get([]byte("name"))