This is an experiment to practice Meta-Programming skills in JavaScript.
- Create a generic Repository implementation (from the Repository Pattern)
- It should be able to 'create', 'update' or 'delete' objects from a MySQL database
- It should not rely on any other parameter aside of the persisted object itself (as an ORM might do).
let conn = createConnection({
connUrl: "mysql:localhost..."
})
let repository = new Repository('Users', conn); // {
// id: 'INTEGER',
// name: 'VARCHAR'
// }
// Table called 'Users' on the database
let User = {}
User.prototype = {
id: null,
name: null
}
let user = new User()
user.id = 1
user.name = 'Mark'
repository.create(user) // new entry into the DB
user.name = 'Miere'
repository.update(user) // update name to be Miere instead of Mark
repository.delete(user) // this entry from the DB will be deleted