2.0.0-beta2 • Published 3 years ago

@loke/mysql-orm v2.0.0-beta2

Weekly downloads
136
License
MIT
Repository
github
Last release
3 years ago

@loke/mysql-orm

NPM Version NPM Downloads License

Breaking Changes

1) You must now import Connection from the module.

Before: const Connection = require("@loke/mysql-orm");

After: const { Connection } = require("@loke/mysql-orm");

2) create and createConnection are gone. Please use Connection.

3) $ operators are gone, as per underlying Sequelize update. You should import Op instead.

Before: myRepo.find({ age: {$gt: 18} })

After:

const { Op } = require("@loke/mysql-orm");
myRepo.find({ age: {[Op.gt]: 18} })

1) You can still use $ operators by declaring them in the connection options using the field operatorsAliases. See sequelize documentation for more details.

Install

npm install @loke/mysql-orm

Example

const { Connection } = require('@loke/mysql-orm');
const db = new Connection('mysql://root@localhost/demo');
const petRepository = db.table('Pets', {
  name: { type: String, defaultValue: () => 'Untitled' },
  description: db.Text
});
const userRepository = db.table('Users', {
  firstName: db.String,
  lastName: db.String,
  pets: [petRepository]
});

userRepository.find({firstName: 'Testing'})
  .then(function (users) {
    users[0].pets[0].description = 'Hello World!';
    // Save changes:
    return userRepository.persist(users[0]);
  });

View Documentation.

Tests

npm test

Coverage

npm run coverage

2.0.0-beta2

3 years ago

2.0.0-beta1

3 years ago

1.13.1

6 years ago

1.13.0

7 years ago

1.12.0

7 years ago