ReplDB interfacing options for ReplAPI.it
rayhanadev opened this issue ยท comments
One idea no Replit API package has managed so far (to my knowledge), is an interfacing option with ReplDB. I don't quite mean enveloping the ReplDB package with ReplAPI.it, but rather sending requests to the endpoint.
Ideas:
- First initialize a ReplDB class, parameter can be to supply the endpoint URL
- Use the normal functions (set, get, delete, list), just like the current ReplDB package
- Add more utility functions?
This doesn't do much with just the basic functions and it could possibly be easier for users if there are utilities...
Pushed an update (2.0.8 on 4/25/2021) with the Database as an Experimental Feature. To use it, turn on Experimental Features.
The Database class will support ReplDB functions or the new ReplDB+ setup for ReplDB (in development by me).
What is ReplDB+?
Unlike the original ReplDB, ReplDB+ is an opinionated, easy-to-use database built on top of the existing ReplDB setup. It will hopefully include many features that give ReplDB a feel similar to a modern database. Modeled after Cloud Firestore, ReplDB+ is a NoSQL database with collections that contain documents of data. It will have more expressive functions, ease-of-life methods, privacy features, and more!
Current usage:
- Database.constructor(dblink, salt, options)
dblink
~ The link to the database, automatically uses thesalt
~ A salt value to use for encrypting the passwordoptions
~ Initialization Options. Used to define the usage of the Database:
{ id: String(dbToken).split('/')[4] || process.env.REPLIT_DB_URL.split('/')[4], // The resource id of the database owner: process.env.REPL_OWNER, // The owner of the database collaborators: { ...options.collaborators }, // Usernames and access levels of collaborators of the database password: { ...hash(String(options.password), String(salt)) }, // Password to use the database type: options.type, // Type of database (currently accepts "repldb" or "plus") encrypted: options.encrypted || [false], // Whether or not to use encryption on the database 'max-items': options['max-items'] || 10, // Maximum items in pagination }
Of course, none of these do anything right now.
Current Database Functions
Database.init()
~ Initialize the database. IMPORTANT database initialization with ReplAPI.it will only occur one time. After that, if it detects configuration exists on the database the function gets ignored. The program will throw an error if it doesn't find a "createDatabaseFlag" value in the .replapirc.json configuration files in order to prevent accidental initialization.Database.createCollection(collectionName)
~ Create a collectionDatabase.createDoc(collectionName, docName, docItems)
~ Create a document in a collectionDatabase.getCollection(collectionName)
~ Get all documentsDatabase.getDoc(collectionName, docName)
~ Get a specific document in a collectionDatabase.updateDoc(collectionName, docName, docItems)
~ Overwrite contents in a documentDatabase.delete(key)
~ DO NOT USE This is placeholder with a incorrect function
More to come!
Some (hopefully) planned features:
Deletion
Database.deleteCollection()
Database.deleteDoc()
Database.deleteField()
Security
Database.encrypt()
- Reading and Writing Access defined in initialization options.
- Password to access database
Ease of life Functions
- Dynamic Queries (documents
.where('votes', '>', '100')
returning documents meeting criteria) - Ordering/Sorting Database
- Pagination on Read?
Here are the database options, except easier on the eyes:
When you initialize a Database (using constructor)
{
password: '', // <String> (required) A password to use to access the database
type: '', // <String> (required) The type of database; options include "repldb" or "plus"
collaborators: {}, // <Object> (optional) The collaborators on a database (see below)
encrypted: [], // <Array> (optional) Whether to use encryption automatically (see below)
'max-items': 0, // <Integer> (optional)
}
In the background, these are the options that are coded into the database:
{
id: String(dbToken).split('/')[4] || process.env.REPLIT_DB_URL.split('/')[4],
owner: process.env.REPL_OWNER,
collaborators: { ...options.collaborators } || {},
password: {
hashedpassword: '',
salt: ''
},
type: '',
encrypted: options.encrypted || [false],
'max-items': options['max-items'] || 10,
}
What do you put in the collaborator field?
collaborators: {
'name-of-collaborator': {
'access': 'read'
}
}
or:
collaborators: {
'name-of-collaborator': {
'access': ['read', 'write']
}
}
What do you put in the encrypted field?
encrypted: [true, 'name-of-encryption']
or:
encrypted: [false]
Added deletion features :)
Deletion
Database.deleteCollection(collectionName)
Database.deleteDoc(collectionName, docName)
Database.deleteField(collectionName, docName, path-to-field)