# emysql **Repository Path**: aiclouddigit/e-mysql ## Basic Information - **Project Name**: emysql - **Description**: 🛠️ Based on mysql basic secondary packaging, the pursuit of creating a simple and easy to use mysql-ORM library - **Primary Language**: TypeScript - **License**: MIT - **Default Branch**: master - **Homepage**: http://emysql.dpapejs.cn/ - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2024-05-23 - **Last Updated**: 2026-10-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # @aicblock/esql ![npm](https://img.shields.io/npm/v/@aicblock/esql) ![npm](https://img.shields.io/npm/dm/@aicblock/esql) ![NPM](https://img.shields.io/npm/l/@aicblock/esql) #### Description 🛠️ Based on the basic secondary package of `mysql2`/`pg`, the pursuit of creating a simple and easy to use `SQL-ORM` library. Supports MySQL and PostgreSQL. #### Installation ```sh npm i @aicblock/esql@latest -S ``` #### Instructions **MySQL Usage:** ```ts import esql, { DefineTable } from '@aicblock/esql' // Reference library // Function instantiation const mysql = new esql({ connConfig: { host: 'localhost', port: 3306, user: 'root', password: 'password', database: 'my_db' } }) ``` **PostgreSQL Usage:** ```ts import esql, { DefineTable } from '@aicblock/esql' const pg = new esql({ connConfig: { host: 'localhost', port: 5432, user: 'postgres', password: 'password', database: 'my_db' }, dialect: 'postgresql' }) await pg.init() ``` #### Logging The default `log: 'none'` is silent. Levels are cumulative: | `log` | Output | | --- | --- | | `none` | Nothing | | `error` | Database operation and connection errors | | `warn` / `info` | Legacy options; currently emit errors only | | `debug` | Errors, pool and transaction events, and slow SQL operations with duration; no full SQL text | | `trace` | Everything in `debug`, plus every SQL statement in full | `slowQueryMs` defaults to 1000 ms; slow operation warnings appear at `debug` and `trace`. Logs go to stderr by default. You can inject a logger with optional `error`, `warn`, `debug`, and `trace` methods: ```ts const db = new esql({ connConfig, log: 'debug', slowQueryMs: 500, logger: { error: (...args) => appLogger.error(...args), warn: (...args) => appLogger.warn(...args), debug: (...args) => appLogger.debug(...args), trace: (...args) => appLogger.trace(...args) } }) ``` Missing logger methods suppress their corresponding messages. Bound parameter values are not logged separately; literals embedded in raw SQL strings appear in `trace` output. #### Backward Compatibility `emysql` is exported as an alias of `esql`, existing code works without modification: ```ts import emysql from '@aicblock/esql' // Still works, default dialect is mysql ```