Registry / database / theorm

theorm

JSON →
library0.2.13jsnpmunverified

theorm is a Node.js MySQL ORM that provides a simple, model-based approach to interacting with MySQL databases. The current stable version is 0.2.13, released as a work-in-progress. It supports a variety of primitive property types (bool, int, char, etc.) with automatic column type mapping and indexing options. Unlike larger ORMs like Sequelize or TypeORM, theorm is lightweight and focuses on MySQL only, with no dependency on TypeScript. It offers built-in search mapping and auto-increment primary key types. The library is still early stage, with limited documentation and community support.

npm install theorm
INSTALL
IMPORT
SIG · THEORM
T
theorm
databasejavascriptv0.2.13
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.

Model
✓ import { Model } from 'theorm'
✗ const { Model } = require('theorm');
theorm supports both ESM and CommonJS. Use named import for ESM.
type
✓ import { type } from 'theorm'
✗ const type = require('theorm').type;
type is a named export containing all primitive type definitions.
connect
✓ import { connect } from 'theorm'
Function to establish a MySQL connection. Required before using models.
db
✓ import { db } from 'theorm'
db is a utility object for raw queries or transaction management.

Shows how to define a model with various property types, create a record, and query using primary key find and where clause.

import { Model, type, connect } from 'theorm'; const dbConfig = { host: process.env.MYSQL_HOST ?? 'localhost', user: process.env.MYSQL_USER ?? 'root', password: process.env.MYSQL_PASSWORD ?? '', database: process.env.MYSQL_DATABASE ?? 'test' }; await connect(dbConfig); class User extends Model { static tableName = 'users'; static fields() { return { id: type.primary_key(), name: type.varchar({ size: 100 }), email: type.varchar({ size: 255, index: true }), age: type.int({ allow_null: true }), active: type.bool_true() }; } } const user = new User(); user.name = 'John'; user.email = 'john@example.com'; user.age = 30; await user.save(); console.log('User saved with id:', user.id); const foundUser = await User.find(1); console.log(foundUser.name); const users = await User.where({ active: true }); console.log(users.length);
Debug
Known issues
breakingModel.fields() must be a static method returning an object; using instance method will cause undefined behavior.
fix
Define 'static fields()' in the class instead of a regular method.
affects: >=0.1.0
gotchaThe 'connect' function must be called before any model operations; otherwise operations throw an error.
fix
Call await connect(config) at application startup.
affects: >=0.1.0
gotchaDefault values for boolean fields: type.bool_true() defaults to true, type.bool_false() defaults to false, but type.bool() defaults to 0 (false).
fix
Explicitly set default_value or use specific type variants.
affects: >=0.1.0
deprecatedThe 'string_key' option in char types is deprecated and may be removed in future versions.
fix
Avoid using string_key; use separate primary key with char instead.
affects: >=0.2.0
Errors
Common errors & fixes
TypeError: Model.find is not a function
Model class not properly defined or static methods not available due to incorrect inheritance.
fix
Ensure class extends Model and call connect() before any find operation.
Error: Connection not established. Call connect() first.
Attempted to use model before calling connect().
fix
Add await connect(config) at the beginning of your application.
TypeError: Cannot read properties of undefined (reading 'type')
Importing incorrectly; type is a named export.
fix
Use import { type } from 'theorm' or const { type } = require('theorm').
Upgrade
Version history
0.2.13latest on npm
Audit
Dependencies
mysql2requiredMySQL database driver required for database operations.
Agent activity
20 hits · last 30 days
node
16
Amazon
1
Anthropic
1
OpenAI (training)
1
Resources
packagetheorm ↗
theorm — npm install theorm · libregistry