als-model v0.8.27 provides an instrument for MySQL and SQLite database operations, including queries, migrations, and fake data generation. It offers a chaining API for building SQL statements (SELECT, WHERE, UPDATE, DELETE, INSERT) with promise or callback support. The library also includes a Migration tool for creating/dropping tables and a Types module for field type definitions. Released as a JavaScript package, it targets Node.js environments and does not bundle TypeScript types. Key differentiators include a simple object-based condition syntax supporting AND/OR logic, and a single Model class that works with both MySQL and SQLite.
npm install als-modelNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to connect to MySQL, create a table via Migration, insert a record, and query using the chaining API with callbacks.
Only use `first()` after `all()` or `where()`. For `insert()`, `update()`, `delete()`, use `run()` or `async()` directly.
Use explicit OR conditions with the '|' prefix as documented. For complex queries, consider writing raw SQL via `query` or `queryAsync`.
Assign the result: `let userModel = model.model('users');`Use `async()` with `await` instead of callbacks for better error handling.
Sanitize inputs before passing to model methods. Consider using parameterized queries when possible (currently not supported by als-model).
Use `const { Model } = require('als-model');` instead of `const Model = require('als-model');`Install the corresponding driver: `npm install mysql` or `npm install sqlite3`
Use `run()` or `async()` after `insert()`/`update()`/`delete()`. `first()` is only available after `all()` or `where()`.
Ensure condition values are strings with operators like '>', '<', etc. For example: `{age: '>25'}`. Also escape special characters if needed.