Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

ReplDB interfacing options for ReplAPI.it #25

Open
rayhanadev opened this issue Apr 8, 2021 · 4 comments
Open

ReplDB interfacing options for ReplAPI.it #25

rayhanadev opened this issue Apr 8, 2021 · 4 comments

Comments

@rayhanadev
Copy link
Collaborator

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...

@rayhanadev
Copy link
Collaborator Author

rayhanadev commented Apr 25, 2021

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 the
    • salt ~ A salt value to use for encrypting the password
    • options ~ 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 collection
  • Database.createDoc(collectionName, docName, docItems) ~ Create a document in a collection
  • Database.getCollection(collectionName) ~ Get all documents
  • Database.getDoc(collectionName, docName) ~ Get a specific document in a collection
  • Database.updateDoc(collectionName, docName, docItems) ~ Overwrite contents in a document
  • Database.delete(key) ~ DO NOT USE This is placeholder with a incorrect function

More to come!

@rayhanadev
Copy link
Collaborator Author

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?

@rayhanadev rayhanadev pinned this issue Apr 28, 2021
@rayhanadev
Copy link
Collaborator Author

rayhanadev commented Apr 28, 2021

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]

@rayhanadev
Copy link
Collaborator Author

Added deletion features :)

Deletion

  • Database.deleteCollection(collectionName)
  • Database.deleteDoc(collectionName, docName)
  • Database.deleteField(collectionName, docName, path-to-field)

@rayhanadev rayhanadev unpinned this issue Jun 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant