Skip to content

Instantly share code, notes, and snippets.

@joeljuca
Created September 5, 2018 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeljuca/8dcf23b8cfd6301e9633e4b6961e5a02 to your computer and use it in GitHub Desktop.
Save joeljuca/8dcf23b8cfd6301e9633e4b6961e5a02 to your computer and use it in GitHub Desktop.

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:

Different classes for different representations

Each one being loaded separatedly:

const { Database, Collection, Entity } = require('entity')

Creating a database by instantiating Database

// `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' })

Creating a collection by instantiating Collection

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' })

Creating an entity by instantiating Entity

// 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' })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment