Registry / database / orma
library1.0.282jsnpmunverified

Orma is a JSON-based, statically typed query language for SQL databases that converts parsable, serializable, and type-safe JSON syntax into SQL strings. It supports MySQL, PostgreSQL, and SQLite, offering features like validation, multi-tenancy, database introspection, declarative foreign keys, nested queries and mutations, mixed operations, dynamic types, batching, and query planning. Version 1.0.282 is the current stable version, with frequent releases. Unlike other ORMs, Orma is pure JS with no code generation and allows use of your own database connector.

npm install orma
INSTALL
IMPORT
SIG · ORMA
O
orma
databasejavascriptv1.0.282
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.

orma_query
import { orma_query } from 'orma'
const orma_query = require('orma').orma_query
ESM-only; named import
orma_mutate
import { orma_mutate } from 'orma'
import orma_mutate from 'orma'
ESM-only; named import, not default
get_mutation_diff
import { get_mutation_diff } from 'orma'
const { get_mutation_diff } = require('orma')
ESM-only; named import
mysql2_adapter
import { mysql2_adapter } from 'orma'
import { mysql2Adapter } from 'orma'
Exact name; no camelCase conversion
orma_schema
import { orma_schema } from 'orma'
import ormaSchema from 'orma'
ESM-only; named import, not default

Shows querying users with their posts and creating a new user using Orma's JSON syntax with mysql2 adapter.

import { orma_query, orma_mutate, get_mutation_diff, mysql2_adapter, orma_schema } from 'orma'; import mysql from 'mysql2'; const pool = mysql.createPool({ host: process.env.DB_HOST ?? 'localhost', port: parseInt(process.env.DB_PORT ?? '3306'), user: process.env.DB_USER ?? 'root', password: process.env.DB_PASS ?? '', database: process.env.DB_NAME ?? 'test', multipleStatements: true, }).promise(); const ormaSql = mysql2_adapter(pool); const query = { users: { id: true, first_name: true, email: true, posts: { id: true, title: true, views: true } } }; const results = await orma_query(ormaSql, query, orma_schema); console.log(results); // Mutation example const mutation = { users: { create: [ { first_name: 'Jane', email: 'jane@example.com' } ] } }; const diff = get_mutation_diff(mutation, results); await orma_mutate(ormaSql, diff, orma_schema);
Debug
Known issues
breakingOrma requires the database connection to have `multipleStatements: true` enabled.
fix
Set `multipleStatements: true` in your pool configuration.
affects: >=0.1
gotchaAll imports are named, not default. Attempting default import will result in undefined.
fix
Use named imports like `import { orma_query } from 'orma'`.
affects: >=1.0
gotchaThe mysql2_adapter function must be called with a promise-based pool; callback-style pool will not work.
fix
Use `pool.promise()` to get the promise-based interface.
affects: >=1.0
Errors
Common errors & fixes
TypeError: orma_query is not a function
Default import used instead of named import.
fix
Replace `import orma from 'orma'` with `import { orma_query } from 'orma'`.
Error: ER_MULTIPLE_STATEMENTS_DISABLED: Multiple statements are not allowed
Database pool not configured with `multipleStatements: true`.
fix
Add `multipleStatements: true` to the pool configuration.
TypeError: pool.query is not a function
mysql2_adapter received a callback-based pool instead of promise-based.
fix
Call `pool.promise()` and pass the result to mysql2_adapter.
Upgrade
Version history
1.0.282latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
packageorma
orma — npm install orma · libregistry