{"name":"leoric","version":"2.16.0","description":"yet another JavaScript object-relational mapping library","browser":"dist/browser.js","main":"lib/index.js","types":"lib/index.d.ts","typesVersions":{"<=4.9":{"lib/*":["types/ts4.9/*"]}},"exports":{".":{"types":"./lib/index.d.ts","import":"./dist/index.js","require":"./lib/index.js"}},"scripts":{"build:types:ts4.9":"node scripts/build-ts49-types.js","prejsdoc":"npm run prepack","jsdoc":"rm -rf docs/api && jsdoc -c .jsdoc.json -d docs/api -t node_modules/@cara/minami","clean":"tsc -b --clean","lint-staged":"lint-staged","prepack":"tsc && npm run build:types:ts4.9","build:playground":"node docs/build-playground.mjs","docs:llms":"node scripts/build-llms.mjs","benchmark":"npm run benchmark:model-compilation","benchmark:proxy":"tsc && node --expose-gc benchmarks/proxy-class-fields.js","benchmark:model-compilation":"tsc && node --expose-gc benchmarks/model-compilation.js","prepack:browser":"rm -rf dist && tsc -p tsconfig.esm.json && node scripts/fix-esm-imports.js","prepublishOnly":"npm run prepack && npm run test:esm","pretest":"tsc && ./test/prepare.sh","test":"./test/start.sh","test:local":"./test/start.sh","test:unit":"./test/start.sh unit","test:esm":"npm run prepack:browser && node test/esm-entry.test.mjs","test:integration":"./test/start.sh integration","test:mysql":"./test/start.sh test/integration/mysql.test.js","test:mysql2":"./test/start.sh test/integration/mysql2.test.js","test:postgres":"./test/start.sh test/integration/postgres.test.js","test:sqlite":"./test/start.sh test/integration/sqlite.test.js","test:sqljs":"./test/start.sh test/integration/sqljs.test.js","test:custom":"./test/start.sh test/integration/custom.test.js","test:sqlcipher":"./test/start.sh test/integration/sqlcipher.test.js","test:file":"./test/start.sh","test:dts":"./test/start.sh dts","test:dts:ts4.9":"npm run build:types:ts4.9 && npm --prefix test/fixtures/ts49-consumer install --no-package-lock && npm --prefix test/fixtures/ts49-consumer run build","test:dts:ts5":"npm run prepack && npm --prefix test/fixtures/ts5-consumer install --no-package-lock && npm --prefix test/fixtures/ts5-consumer run build","test:coverage":"nyc ./test/start.sh && nyc report --reporter=lcov","lint":"eslint ./","lint:fix":"eslint . --fix","prepare":"husky install"},"repository":{"type":"git","url":"git+https://github.com/cyjake/leoric.git"},"keywords":["model","mysql","orm","postgresql","query builder","sqlite"],"maintainers":[{"name":"dotnil","email":"jakeplus@gmail.com"},{"name":"jimmydaddy","email":"heyjimmygo@gmail.com"}],"license":"BSD-3-Clause","engines":{"node":">= 18.0.0"},"lint-staged":{"*.{js,ts}":["eslint --no-ignore --fix"]},"nyc":{"extends":"@istanbuljs/nyc-config-typescript","include":["src"]},"dependencies":{"dayjs":"^1.10.3","debug":"^3.1.0","deep-equal":"^2.0.5","pluralize":"^7.0.0","reflect-metadata":"^0.1.13","sqlstring":"^2.3.0","tslib":"^2.5.0","validator":"^13.5.2"},"peerDependencies":{"mysql":"^2.17.1","mysql2":"^2.3.0 || ^3.9.4","pg":"^8.5.1","sql.js":"^1.8.0","sqlite3":"^5.0.2"},"peerDependenciesMeta":{"mysql":{"optional":true},"mysql2":{"optional":true},"pg":{"optional":true},"sqlite3":{"optional":true},"sql.js":{"optional":true}},"devDependencies":{"@babel/core":"^7.14.6","@babel/eslint-parser":"^7.14.7","@cara/minami":"^1.2.3","@istanbuljs/nyc-config-typescript":"^1.0.2","@journeyapps/sqlcipher":"^5.2.0","@tsconfig/node18":"^18.2.4","@types/debug":"^4.1.12","@types/mocha":"^9.0.0","@types/node":"^18.19.130","@types/pluralize":"^0.0.33","@types/sinon":"^10.0.20","@types/sql.js":"^1.4.4","@types/sqlstring":"^2.3.2","@typescript-eslint/eslint-plugin":"^5.59.2","@typescript-eslint/parser":"^5.59.2","esbuild":"^0.28.1","eslint":"^8.52.0","eslint-plugin-no-only-tests":"^3.0.0","expect.js":"^0.3.1","husky":"^8.0.3","jsdoc":"^4.0.2","lint-staged":"^13.2.2","mocha":"^10.2.0","mysql":"^2.17.1","mysql2":"^3.15.2","nyc":"^15.1.0","pg":"^8.5.1","sinon":"^10.0.0","sql.js":"^1.8.0","sqlite3":"^5.0.2","taffydb":"^2.7.3","ts-node":"^10.9.2","typescript":"^5.9.2"},"overrides":{"sqlite3":{"glob":"11.0.0","node-gyp":"10.2.0"}},"gitHead":"ddf2398bb7f42fde1f218a2a9180562891bac892","_id":"leoric@2.16.0","bugs":{"url":"https://github.com/cyjake/leoric/issues"},"homepage":"https://github.com/cyjake/leoric#readme","_nodeVersion":"24.19.0","_npmVersion":"11.17.0","dist":{"integrity":"sha512-qF+Hhww/DDL168QPz/Ve6nHQU9boBbMz9nLV8Rl8ZEPY4EhsQl1eW8mtO4pQcpN+UFdEsnXcISLkI7Th0p1WOw==","shasum":"ffa4308972744298582422039598d15ac3a8288e","tarball":"http://registry-npm.ywwl.com/leoric/download/leoric-2.16.0.tgz","fileCount":261,"unpackedSize":1716636,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/leoric@2.16.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDlAlOcxSJmDnZsLCZrDeuAIak8AtVeLhbuc4tgsTV8bwIhALnuzeyQzwk1mpyg3YgOHPIGNH6MhgOyBquM4+en4Sid"}],"size":339623,"noattachment":false,"key":"/leoric/-/leoric-2.16.0.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:ab37ba12-2bca-408f-908f-f19b870b963b"}},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/leoric_2.16.0_1787033776307_0.5904385892388591"},"_hasShrinkwrap":false,"readme":"# Leoric\n\n[![Package Quality](https://packagequality.com/shield/leoric.svg)](https://packagequality.com/#?package=leoric)\n[![NPM Downloads](https://img.shields.io/npm/dm/leoric.svg?style=flat)](https://www.npmjs.com/package/leoric)\n[![NPM Version](http://img.shields.io/npm/v/leoric.svg?style=flat)](https://www.npmjs.com/package/leoric)\n[![Build Status](https://github.com/cyjake/leoric/actions/workflows/nodejs.yml/badge.svg)](https://github.com/cyjake/leoric/actions/workflows/nodejs.yml)\n[![codecov](https://codecov.io/gh/cyjake/leoric/branch/master/graph/badge.svg?token=OZZWTZTDS1)](https://codecov.io/gh/cyjake/leoric)\n\nLeoric is an object-relational mapping library for Node.js, which is heavily influenced by Active Record of Ruby on Rails. See the [documentation](https://leoric.js.org) for detail.\n\n## Usage\n\nAssume the tables of posts, users, and comments were setup already. We may declare the models as classes by extending from the base class `Bone` of Leoric. After the models are connected to the database, the columns of the tables are mapped as attributes, the associations are setup, feel free to start querying.\n\n```js\nimport Realm, { Bone } from 'leoric'\n\nconst realm = new Realm({ host: 'example.com' })\nconst Post = realm.define(class Post extends Bone {\n  static initialize() {\n    this.belongsTo('author', { Model: 'User' })\n    this.hasMany('comments')\n  }\n})\n\nasync function main() {\n  // connect models to database\n  await realm.connect()\n\n  // CRUD\n  await Post.create({ title: 'New Post' })\n  const post = await Post.findOne({ title: 'New Post' })\n  post.title = 'Untitled'\n  await post.save()\n\n  // or UPDATE directly\n  await Post.update({ title: 'Untitled' }, { title: 'New Post' })\n\n  // find with associations\n  const post = await Post.findOne({ title: 'New Post' }).with('comments')\n  console.log(post.comments) // => [ Comment { id, content }, ... ]\n}\n```\n\nIf table structures were intended to be maintained in the models, Leoric can be used as a table migration tool as well. We can just define attributes in the models, and call `realm.sync()` whenever we are ready.\n\n```js\nimport Realm, { Bone, DataTypes } from 'leoric';\nconst { BIGINT, STRING } = DataTypes;\nconst realm = new Realm();\nconst Post = realm.define(class Post extends Bone {\n  static attributes = {\n    id: { type: BIGINT, primaryKey: true },\n    email: { type: STRING, allowNull: false },\n    nickname: { type: STRING, allowNull: false },\n  }\n});\n\nawait realm.sync();\n```\n\n## Syntax Table\n\n| JavaScript                              | SQL                                                |\n|-----------------------------------------|----------------------------------------------------|\n| `Post.create({ title: 'New Post' })`    | `INSERT INTO posts (title) VALUES ('New Post')`    |\n| `Post.all`                              | `SELECT * FROM posts`                              |\n| `Post.find({ title: 'New Post' })`      | `SELECT * FROM posts WHERE title = 'New Post'`     |\n| `Post.find(42)`                         | `SELECT * FROM posts WHERE id = 42`                |\n| `Post.order('title')`                   | `SELECT * FROM posts ORDER BY title`               |\n| `Post.order('title', 'desc')`           | `SELECT * FROM posts ORDER BY title DESC`          |\n| `Post.limit(20)`                        | `SELECT * FROM posts LIMIT 0, 20`                  |\n| `Post.update({ id: 42 }, { title: 'Skeleton King' })` | `UPDATE posts SET title = 'Skeleton King' WHERE id = 42` |\n| `Post.remove({ id: 42 })`               | `DELETE FROM posts WHERE id = 42`                  |\n\nA more detailed syntax table may be found at the [documentation](https://leoric.js.org/#syntax-table) site.\n\n## TypeScript charged\n\n```ts\nimport { Bone, BelongsTo, Column, DataTypes: { TEXT } } from 'leoric';\nimport User from './user';\n\nexport default class Post extends Bone {\n  @Column({ autoIncrement: true })\n  declare id: bigint;\n\n  @Column(TEXT)\n  declare content: string;\n\n  @Column()\n  declare description: string;\n\n  @Column()\n  declare userId: bigint;\n\n  @BelongsTo()\n  declare user: User;\n}\n```\n\nMore about TypeScript integration examples can be found at [the TypeScript support documentation](https://leoric.js.org/types)\n\n## AI-Friendly Resources\n\nLeoric is designed to work well with AI coding assistants, both for end users and for contributors:\n\n- [AI Cookbook](https://leoric.js.org/ai-cookbook) (中文：[AI 代码手册](https://leoric.js.org/zh/ai-cookbook)) — copy-pasteable, verified patterns for models, queries, transactions, and troubleshooting\n- [llms.txt](https://leoric.js.org/llms.txt) — machine-readable index of the documentation\n- [llms-full.txt](https://leoric.js.org/llms-full.txt) / [llms-full-zh.txt](https://leoric.js.org/llms-full-zh.txt) — all guides concatenated for single-shot context injection\n- These files are also shipped inside the npm package (`node_modules/leoric/llms-full.txt` etc.), so AI assistants in offline or private-registry environments can still read the full documentation\n- [AGENTS.md](./AGENTS.md) (中文版：[AGENTS.zh-CN.md](./AGENTS.zh-CN.md)) — repository guide for AI agents and contributors\n- Public API types ship with JSDoc, so IDE autocompletion and AI code generation see documented signatures out of the box\n\n## Contributing\n\nThere are many ways in which you can participate in the project, for example:\n\n- [Submit bugs and feature requests](https://github.com/cyjake/leoric/issues), and help us verify as they are checked in\n- [Review source code changes](https://github.com/cyjake/leoric/pulls)\n- Review the [documentation](https://leoric.js.org) and make pull requests for anything from typo to new content\n\nIf you are interested in fixing issues and contributing directly to the code base, please see the document [How to Contribute](https://leoric.js.org/contributing/guides), which covers the following:\n\n- The development workflow, including debugging and running tests\n- Coding guidelines\n- Submitting pull requests\n- Contributing to translations\n\n## egg-orm\n\nIf developing web applications with [egg framework](https://eggjs.org/), it's highly recommended using the [egg-orm](https://github.com/eggjs/egg-orm) plugin. More detailed examples about setting up egg-orm with egg framework in either JavaScript or TypeScript can be found at <https://github.com/eggjs/egg-orm/tree/master/examples>\n\n## mysql nuances\n\nmacOS binds localhost to ipv6 `::1`, yet both mysql and mysql2 connect database with localhost by default, which means both will try connecting to mysql with `::1`. However, the mysql distribution installed with HomeBrew sets `bind_address = 127.0.0.1`, hence causes following error:\n\n```js\nError: connect ECONNREFUSED ::1:3306\n  at __node_internal_captureLargerStackTrace (node:internal/errors:490:5)\n  at __node_internal_exceptionWithHostPort (node:internal/errors:668:12)\n  at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)\n```\n\nPlease change the configuration as below:\n\n```diff\ndiff --git a/usr/local/etc/my.cnf b/usr/local/etc/my.cnf\nindex 7218354..d31859c 100644\n--- a/usr/local/etc/my.cnf\n+++ b/usr/local/etc/my.cnf\n@@ -1,5 +1,5 @@\n # Default Homebrew MySQL server config\n [mysqld]\n # Only allow connections from localhost\n-bind-address = 127.0.0.1\n+bind-address = 127.0.0.1,::1\n mysqlx-bind-address = 127.0.0.1\n ```\n\n and restart the mysql service:\n\n ```bash\n brew services mysql restart\n ```\n","publish_time":1787033776451,"_cnpm_publish_time":1787033776451,"dist-tags":{"alpha":"2.15.0-alpha.4","beta":"2.15.0-beta.5","latest":"2.16.0"}}