Registry / database / epic-sql

epic-sql

JSON →
library5.0.5jsnpmunverified

Epic SQL (v5.0.5) is a MySQL ORM for Node.js with a focus on simplifying database interactions by eliminating raw SQL queries. It provides a schema-based approach for defining models using custom data types like SQLString and SQLBoolean, with support for indexes, unique constraints, and enums. The library includes a connection manager with sync and logging options. Compared to Sequelize or TypeORM, Epic SQL offers a more minimalistic API and lighter footprint, but has a smaller community and fewer features. Release cadence is irregular; the current version is stable but may lack ongoing development.

npm install epic-sql
INSTALL
IMPORT
SIG · EPIC-SQL
E
epic-sql
databasejavascriptv5.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Schema
import { Schema } from 'epic-sql'
const { Schema } = require('epic-sql')
epic-sql is ESM-only; CommonJS require will not work.
Connector
import { Connector } from 'epic-sql'
import Connector from 'epic-sql'
Connector is a named export, not default.
ConnectionManager
import { ConnectionManager } from 'epic-sql'
import { ConnectionManager } from 'epic-sql/connection'
ConnectionManager is exported from the main package, not a subpath.
SQLString
import { SQLString } from 'epic-sql'
import { SQLString } from 'epic-sql/datatypes'
All datatypes are exported from the root package.
SQLBoolean
import { SQLBoolean } from 'epic-sql'

Creates a schema for users, connects to MySQL, inserts a row, and logs the result.

import { Connector, ConnectionManager, Schema, SQLString, SQLNumber } from 'epic-sql'; const Users = new Schema('users', { userId: new SQLString({ isUnique: true }), name: new SQLString(), age: new SQLNumber(), } as const); (async () => { const connection = await new ConnectionManager( new Connector( { host: 'localhost', user: 'root', password: process.env.DB_PASSWORD ?? '', database: 'test', }, { sync: false, logs: true } ), [Users] ).init(); const User = Users.new(); const newUser = await User.insert({ userId: 'jdoe', name: 'John Doe', age: 30 }); console.log(newUser); connection.getConnector().end(); })();
Debug
Known issues
gotchaThe sync option in Connector options should be false in production; true will drop and recreate tables on each connection.
fix
Set { sync: false } in production environments.
affects: >=0.0.0
breakingSchema must be 'locked' by calling .new() before performing any CRUD operations; calling methods directly on Schema instance throws an error.
fix
Always use Schema.new() to obtain a locked instance.
affects: >=4.0.0
deprecatedThe 'epic' keyword in package.json is no longer supported for registration; use 'epic-sql' directly.
fix
Import from 'epic-sql' instead of 'epic'.
affects: >=5.0.0
Errors
Common errors & fixes
Error: Cannot find module 'epic-sql'
Package not installed or incorrect import path.
fix
Run 'npm install epic-sql' and ensure the import is 'epic-sql', not a subpath.
TypeError: Users.new is not a function
Schema was not imported correctly or the version is old.
fix
Use import { Schema } from 'epic-sql' and instantiate correctly: const Users = new Schema('users', {...}); Users.new();
ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
MySQL credentials are incorrect or the user lacks permissions.
fix
Verify host, user, and password in Connector config. Ensure the MySQL server is running and accepts connections.
Upgrade
Version history
5.0.5latest on npm
Audit
Dependencies
mysql2requiredrequired for MySQL database connectivity
Agent activity
10 hits · last 30 days
node
8
Resources
epic-sql — npm install epic-sql · libregistry