Skip to content

Instantly share code, notes, and snippets.

@EnetoJara
Created May 23, 2020 23:42
Show Gist options
  • Save EnetoJara/92aee8dfe2933c2ab383512db5c17625 to your computer and use it in GitHub Desktop.
Save EnetoJara/92aee8dfe2933c2ab383512db5c17625 to your computer and use it in GitHub Desktop.
import { AccountAttributes, Repository } from "@eneto/models";
import { DataTypes, Sequelize } from "sequelize";
/**
* Account factory
*
* @param {import("sequelize").Sequelize} sequelize Sequelize database instance.
* @returns {Repository<AccountAttributes>} Instance of Accounts Entity.
*/
function AccountFactory(sequelize: Sequelize): Repository<AccountAttributes> {
return sequelize.define(
"accounts",
{
id: {
type: DataTypes.BIGINT,
allowNull: false,
unique: true,
primaryKey: true,
autoIncrement: true,
},
username: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
psswrd: {
type: DataTypes.STRING,
allowNull: false,
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
},
},
{
freezeTableName: true,
}
) as Repository<AccountAttributes>;
}
export { AccountFactory };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment