This is a discussion issue. Tasks will be defined after this discussion issue is closed.
Currently, our Entity library is pretty simple and primitive. It only supports a single database per program, and there's no distinction between a database and a row. Ideally, we would have a clear distinction between representations of a database, a row, and a collection of rows (eg.: a table), so we could use object-oriented programming to properly represent every single aspect of a database (for now, we'll be focused in databases, collections/tables, and rows/documents).
Below are examples of how I imagine it could be:
Each one being loaded separatedly:
const { Database, Collection, Entity } = require('entity')
// `db` would be an instance of Database that points to the JSON file `path/to/database.json`
const db = new Database({ filePath: 'path/to/database.json' })
FYI: it would be equivalent to a table in the RDBMS world.
// `Users` would be a representation of a collection of entities (e.g.: a database table)
const Users = new Collection({ database: db, table: 'users' })
// the collection above could alternatively be created with a helper method from Database:
const Users = new db.createCollection({ table: 'users' })
// An entity document would be a single information - like a database row
const user = new Entity({
collection: Users,
entity: {
username: 'joelwallis'
}
})
// the collection above could alternatively be created with a helper method from Collection:
const user = Users.create({ username: 'joelwallis' })