0.0.8 • Published 6 years ago

numfin-sequelize v0.0.8

Weekly downloads
10
License
ISC
Repository
github
Last release
6 years ago

Ez types with Sequelize!

Example:

Create Sequelize instance:

// database.util.ts
import Sequelize from 'sequelize';

export const db = new Sequelize('db', 'user', 'password', {
  host: 'localhost',
  port: port,
  dialect: 'postgres',
  operatorsAliases: false,
});

Create model:

// user.model.ts
import { db } from '../database.util';
import { CreateModel, Types } from 'numfin-sequelize';

export class UserType {
  name = Types.STRING();
  // second argument of Types.UUID gives you
  // ability to make it autogenerated
  id = Types.UUID({ primaryKey: true }, true);
}
export const User = CreateModel(db, 'users', UserType);

How to use it:

// index.main.ts
import { db } from '../database.util';
import { User } from '../user.model.ts';

db.sync().then(async () => {
  // autocomplete for User fields is here
  await User.create({ name: 'hi' }); // done!
});

If anything wrong - write in issues