orange-dragonfly-orm-mysql
v0.8.0
Published
MySQL Driver for Orange Dragonfly ORM
Maintainers
Readme
Orange Dragonfly ORM MySQL Driver
MySQL driver for Orange Dragonfly ORM.
Installation
npm i orange-dragonfly-orm
npm i orange-dragonfly-orm-mysqlUsage
import { AbstractQuery, ActiveRecord, Relation } from 'orange-dragonfly-orm'
import MySQLDriver from 'orange-dragonfly-orm-mysql'
class Brand extends ActiveRecord {
static get available_relations() {
return {
models: Relation.children(this, this.model('CarModel')),
}
}
}
class CarModel extends ActiveRecord {}
AbstractQuery.registerDB(new MySQLDriver({
host: 'localhost',
port: 3306,
user: 'root',
password: 'secret',
database: 'mydb',
}))
ActiveRecord
.registerModel(Brand)
.registerModel(CarModel)
const brands = await Brand.all()Configuration
| Option | Type | Default | Description |
|---|---|---|---|
| host | string | — | MySQL server hostname |
| port | number | 3306 | MySQL server port |
| user | string | — | Database user |
| password | string | — | Database password |
| database | string | — | Database name |
| charset | string | — | Connection charset |
| connect_timeout | number | 5000 | Connection timeout in ms |
| debug | boolean \| function | — | Log SQL via console.debug or a custom function |
What the driver configures
On connect() the driver sets the following process-wide ORMHelpers properties for MySQL compatibility:
RESERVED_WORDS— full MySQL reserved word list (used to auto-escape identifiers with backticks)ESCAPE_CHAR—`FULL_TEXT_CLAUSE_FN—MATCH(a) AGAINST (b)syntax for fulltext search
These are reset to their defaults on disconnect().
Running tests
Unit tests (no database required):
npm testIntegration tests require a real MySQL instance. Copy the example config and fill in your credentials:
cp test-config.example.json test-config.jsonThen run:
npm run test:integrationtest-config.json is git-ignored and never published.
Closing the connection
import { AbstractQuery } from 'orange-dragonfly-orm'
await AbstractQuery.releaseDB()