@les-desesperes/ensto-db
v1.1.9
Published
Sequelize database module and model manager for Ensto
Maintainers
Readme
@les-desesperes/ensto-db
Sequelize-based database module for Ensto applications.
It provides:
- an
EnstoDatabaseclass for connection lifecycle and model management - built-in Ensto models with associations
- dynamic model registration and schema-based model creation
- a singleton
sequelizeexport for compatibility - crypto helpers for hashing and AES encryption/decryption
Installation
pnpm add @les-desesperes/ensto-dbDocumentation
Detailed usage documentation is available in docs/USAGE.md.
Quick Start
import { EnstoDatabase } from '@les-desesperes/ensto-db';
async function main() {
const db = new EnstoDatabase();
await db.authenticate();
await db.sync();
const employee = await db.models.Employee.create({
username: 'admin',
badgeUuid: 'B053AF25',
passwordHash: 'plain-password',
role: 'Admin',
});
console.log(employee.employeeId);
await db.close();
}
main().catch(console.error);Main Exports
import {
EnstoDatabase,
sequelize,
createSequelizeInstance,
getEnvDatabaseConfig,
initModels,
Employee,
DeliveryDriver,
Vehicle,
Visitor,
HistoryLog,
encryptAES,
decryptAES,
hashSHA256,
} from '@les-desesperes/ensto-db';Built-in Models
EmployeeDeliveryDriverVehicleVisitorHistoryLog
Dynamic Models
import { DataTypes } from 'sequelize';
import { EnstoDatabase } from '@les-desesperes/ensto-db';
const db = new EnstoDatabase();
const Contractor = db.createModel(
'Contractor',
{
contractorId: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true,
},
companyName: {
type: DataTypes.STRING,
allowNull: false,
},
},
{
tableName: 'contractors',
timestamps: false,
}
);Environment Variables
MYSQL_DATABASE=ensto
MYSQL_USER=root
MYSQL_PASSWORD=secret
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
ENCRYPTION_KEY=your-32-byte-secret-key-string!!Development
pnpm install
pnpm run build
pnpm testPublish Notes
This release includes the new EnstoDatabase API and dynamic model support.
See the full guide in docs/USAGE.md before publishing.
