-
-
Notifications
You must be signed in to change notification settings - Fork 76
Database API
P-Brain has a generic key-value storage system for storing data globally, specific to a skill, or specific to a user and skill.
This is just a string representation of the skill.
This object is expected when calling user specific database functions and is passed into queries. It contains the following fields:
- user_id (integer): The unique user ID.
- username (text): The unique username.
- password (text): The hashed and salted password.
- is_admin (boolean): If the user is an admin this is true.
This is just a string representation of the key.
This can be any Javascript object compatible with JSON.stringify().
All function calls to the database are generators. The database object is globally accessible in global.db. This list will contain functions which are most likely to be used when developing a skill. For the full list see sqlite_db/index.js.
Used for things like the users name. If all 3 values are not specified for getValue then it will return an array in the format: [{skill: '<skill>', username: '<username>', key: '<key>', value: '<value>'}]
. If all are specified then it will simply return the value.
- db.setValue(skill, user, key, value)
- db.getValue(skill[optional], [optional], [optional])
This example will get the users name if it is set.
yield global.db.getValue('name', user, 'name')
These are used for config values such as API keys for a skill. If all both values are not specified for getSkillValue then it will return an array in the format: [{skill: '<skill>', key: '<key>', value: '<value>'}]
. If all are specified then it will simply return the value.
- db.setSkillValue(skill, key, value)
- db.getSkillValue(skill[optional], key[optional])
These ones are used for global settings, such as port numbers. If 'key' is not specified for getGlobalValue then it will return an array in the format: [{key: '<key>', value: '<value>'}]
. If all are specified then it will simply return the value.
- db.setGlobalValue(key, value)
- db.getGlobalValue(key)