A database config is only required if you want to be able to read and/or write to your database without using your API key or enable other enhanced functionality. Create a new resource with a name in this format to create a new database config: database_name.db.json (Example: If you want your database name to be chat you’d name the database config file chat.db.json)
Below is an example config file. Take your time to look it over and then scroll down for an explanation.
{
"permissions": {
"read": true,
"write": true,
"auth": true,
"auto_increment": true
},
"fields": {
"logged_in": {
"type": "username"
},
"email": {
"type": "email",
"max_length": 255
},
"link": {
"type": "url",
"max_length": 100
},
"message": {
"type": "text",
"max_length": 200
},
"categories": {
"type": "regex-false",
"regex": "/(1|2|3)/"
}
}
}
permissions→read
is true then your database can be read without an API keypermissions→write
is true then your database can be written to without an API keypermissions→auth
is true only logged in users can write to your database (will only work when querying the API with JavaScript from a 1mb.site subdomain. You must send along browser credentials (aka cookies) for this to work (otherwise it’ll think everybody is logged out)permissions→auto_increment
is true the key parameter won’t be required when calling db-insert. The key name will start at 1 and auto increment with each new entry.In the example the fields
logged_in, email, link, and message are the key names (Make sure the key names match the corresponding JSON keys in set parameter you send)
By enforcing fields you are deciding what data to accept into your database and what data to reject. If anybody tries to submit data that doesn’t correspond with your requirements they’ll see an error.
Here is the types you can choose from: