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.
database
✓ import { database } from 'febs-db'
✗ const database = require('febs-db').database
ESM import with named export; CommonJS require works but TypeScript prefers named import.
tablebase
✓ import { tablebase } from 'febs-db'
✗ const { TableBase } = require('febs-db')
Name is all lowercase; tablebase is the class, not TableBase.
dataType
✓ import { dataType } from 'febs-db'
✗ import DataType from 'febs-db'
dataType is a named export, not default.
condition
✓ import { condition } from 'febs-db'
condition is a class used via tablebase.condition.
exception
✓ import { exception } from 'febs-db'
✗ const { Exception } = require('febs-db')
Export is lowercase 'exception', not 'Exception'.
Shows full CRUD with custom table class, condition builder, transaction, and raw query.
import { database, tablebase, dataType, condition } from 'febs-db';
// Define a table class extending tablebase
class UserTable extends tablebase {
constructor(db) {
super(db, 'user');
// Define columns
this.regColumn({
id: { type: dataType.INTEGER, autoIncr: true },
name: { type: dataType.STRING, length: 50 },
email: { type: dataType.STRING, length: 100 },
created_at: { type: dataType.TIMESTAMP }
});
this.regPrimaryKey('id');
}
}
// Connect to MySQL
const db = new database({
type: 'mysql',
host: process.env.DB_HOST ?? 'localhost',
port: 3306,
user: process.env.DB_USER ?? 'root',
password: process.env.DB_PASS ?? '',
database: 'test'
});
const userTable = new UserTable(db);
async function main() {
// Add a new user
const newId = await userTable.add({ name: 'Alice', email: 'alice@example.com', created_at: new Date() });
console.log('Inserted user id:', newId);
// Query users
const users = await userTable.select(userTable.condition().equal('name', 'Alice'));
console.log('Found users:', users);
// Update
await userTable.update({ email: 'alice@newdomain.com' }, userTable.condition().equal('id', newId));
// Delete
await userTable.remove(userTable.condition().equal('id', newId));
// Transaction
await db.transaction(async () => {
await userTable.add({ name: 'Bob', email: 'bob@example.com' });
});
// Raw query
const rows = await db.exec('SELECT * FROM user');
console.log(rows);
}
main().catch(console.error);
Errors
Common errors & fixes
TypeError: tablebase is not a constructor
Trying to instantiate tablebase directly instead of subclassing it.
fixCreate a subclass: class MyTable extends tablebase { constructor(db) { super(db, 'tablename'); } } Error: DB_SqlException: Unknown column '...' in 'where clause'
Column name used in condition does not match the registered column name.
fixVerify column names: they must match exactly the keys used in regColumn.
Error: DB_ConneException: connect ECONNREFUSED
Database server is not running or connection parameters are incorrect.
fixCheck host, port, and ensure MySQL/MSSQL service is started.
TypeError: Cannot read property 'condition' of undefined
tablebase instance not properly initialized; or using condition() before calling super().
fixEnsure constructor calls super(db, tablename) and that db is a valid database instance.
Audit
Dependencies
mysqlrequiredMySQL driver for database connections
mssqloptionalMSSQL driver for database connections