{"id":13622091,"url":"https://github.com/haltcase/trilogy","last_synced_at":"2025-04-09T19:19:59.736Z","repository":{"id":40277271,"uuid":"64280871","full_name":"haltcase/trilogy","owner":"haltcase","description":"TypeScript SQLite layer with support for both native C++ \u0026 pure JavaScript drivers.","archived":false,"fork":false,"pushed_at":"2022-05-17T01:58:57.000Z","size":1081,"stargazers_count":265,"open_issues_count":7,"forks_count":24,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-09T19:19:55.235Z","etag":null,"topics":["async","database","electron","hacktoberfest","knex","looking-for-contributors","model","nwjs","promise","schema","sql","sql-js","sqlite","typescript"],"latest_commit_sha":null,"homepage":"https://trilogy.js.org","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/haltcase.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":".github/contributing.md","funding":".github/FUNDING.yml","license":"license","code_of_conduct":".github/code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["citycide"]}},"created_at":"2016-07-27T05:51:25.000Z","updated_at":"2025-03-09T21:02:43.000Z","dependencies_parsed_at":"2022-08-12T21:40:09.307Z","dependency_job_id":null,"html_url":"https://github.com/haltcase/trilogy","commit_stats":null,"previous_names":["citycide/trilogy"],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haltcase%2Ftrilogy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haltcase%2Ftrilogy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haltcase%2Ftrilogy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haltcase%2Ftrilogy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haltcase","download_url":"https://codeload.github.com/haltcase/trilogy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094991,"owners_count":21046770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","database","electron","hacktoberfest","knex","looking-for-contributors","model","nwjs","promise","schema","sql","sql-js","sqlite","typescript"],"created_at":"2024-08-01T21:01:13.903Z","updated_at":"2025-04-09T19:19:59.709Z","avatar_url":"https://github.com/haltcase.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/citycide/trilogy/master/media/logo.svg?sanitize=true\" width=\"420\" alt=\"trilogy\"\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://www.npmjs.com/package/trilogy\"\u003e\u003cimg src=\"https://flat.badgen.net/npm/v/trilogy\" alt=\"Version\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/trilogy\"\u003e\u003cimg src=\"https://flat.badgen.net/npm/license/trilogy\" alt=\"License\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://travis-ci.org/citycide/trilogy\"\u003e\u003cimg src=\"https://flat.badgen.net/travis/citycide/trilogy\" alt=\"Travis CI\"\u003e\u003c/a\u003e\n  \u003ca href=\"http://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html\"\u003e\u003cimg src =\"https://flat.badgen.net/badge/written%20in/TypeScript/294E80\" alt=\"Written in TypeScript\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://standardjs.com\"\u003e\u003cimg src=\"https://flat.badgen.net/badge/code%20style/standard/green\" alt=\"JavaScript Standard Style\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://gitter.im/citycide/trilogy\"\u003e\u003cimg src=\"https://flat.badgen.net/badge/chat/on%20gitter/green\" alt=\"Gitter\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n***trilogy*** is a simple Promise-based wrapper for SQLite databases.\nIt supports both the native C++ [`sqlite3`][sqlite3] driver and the pure\nJavaScript [`sql.js`][sqljs] backend \u0026mdash; compile natively for speed\nwhen you need it, or use `sql.js` headache-free in cross-platform environments\nand [Electron][electron] apps.\n\nIt's not an ORM and isn't intended to be one \u0026mdash; it doesn't have any\nrelationship features. Instead it focuses on providing a simple, clear API\nthat's influenced more by [Mongoose][mongoose] than by SQL.\n\n---\n\n[features](#features) \u0026middot; [installation](#installation) \u0026middot; [usage](#usage) \u0026middot; [contributing](#contributing) \u0026middot; [license](#license)\n\n---\n\n## features\n\n* :link: **automatically casts data between JavaScript \u0026 SQLite types**\n\n  Define schemas with types like `String`, `Date`, or `'increments'` \u0026mdash;\n  trilogy will handle all the type-casting involved to map accurately\n  between JavaScript and the underlying SQLite database.\n\n* :battery: **powered by the [knex][knex] query builder**\n\n  trilogy uses knex internally to build its queries, but it's also exposed so\n  you can use it to build your own. No need to mess with ridiculous multi-line\n  strings.\n\n* :nut_and_bolt: **supports multiple swappable backends ( _plus in-memory storage_ )**\n\n  Both the native [`sqlite3`][sqlite3] module _and_ [`sql.js`][sqljs] (pure\n  JavaScript!) are supported. There is also memory-only storage for fast,\n  unpersisted data handling, which is great for tests and performance critical\n  situations.\n\n  You can even swap the backend after you've started, with no changes to the\n  rest of your code!\n\n* :cop: **written in [TypeScript][typescript]**\n\n  trilogy is written in and provides a first-class experience for TypeScript.\n\n* :electric_plug: **lifecycle hooks**\n\n  Any number of hooks (aka subscribers or listeners) can be attached at several\n  points in the lifecycle \u0026mdash; for example `onQuery`, `beforeCreate`, `afterUpdate`.\n  These are useful for debugging and extensibility.\n\n* :revolving_hearts: **perfect for [Electron][electron] \u0026 [NW.js][nwjs]**\n\n  Compiling the `sqlite3` module for all the platforms you target with Electron\n  or NW.js can be difficult. That's why trilogy also supports the `sql.js` backend,\n  which doesn't need to be compiled at all!\n\n## installation\n\n1. Install trilogy\n\n   ```console\n   # using yarn\n   yarn add trilogy\n\n   # using npm\n   npm i trilogy\n   ```\n\n2. Install a backend\n\n   ```console\n   # using yarn\n   yarn add sqlite3\n\n   # using npm\n   npm i sqlite3\n   ```\n\n   _or_\n\n   ```console\n   # using yarn\n   yarn add sql.js\n\n   # using npm\n   npm i sql.js\n   ```\n\n## usage\n\nFull documentation is [available here][docs] and includes guides, an API\nreference, and more.\n\nHere's a quick overview. It uses `async` \u0026 `await` but is easily usable with\nvanilla Promises.\n\n```js\nimport { connect } from 'trilogy'\n\n// defaults to using the `sqlite3` backend\nconst db = connect('./file.db')\n\n// choose `sql.js` to avoid native compilation :)\nconst db = connect('./file.db', {\n  client: 'sql.js'\n})\n\n// set the filename to ':memory:' for fast, in-memory storage\nconst db = connect(':memory:', {\n  // it works for both clients above!\n  client: 'sql.js'\n})\n\n;(async function () {\n  const games = await db.model('games', {\n    name: { type: String },\n    genre: String,            // type shorthand\n    released: Date,\n    awards: Array,\n    id: 'increments'          // special type, primary key\n  })\n\n  await games.create({\n    name: 'Overwatch',\n    genre: 'FPS',\n    released: new Date('May 23, 2016'),\n    awards: [\n      'Game of the Year',\n      'Best Multiplayer Game',\n      'Best ESports Game'\n    ]\n  })\n\n  const overwatch = await games.findOne({ name: 'Overwatch' })\n\n  console.log(overwatch.awards[1])\n  // -\u003e 'Best Multiplayer Game'\n})()\n```\n\n## contributing\n\nThis project is open to contributions of all kinds! Don't worry if you're\nnot 100% up to speed on the process \u0026mdash; there's a short outline in the\n[Contributor Guide](.github/contributing.md).\n\nYou'll also find a reference for the set of labels used to categorize issues,\nwith descriptions of each.\n([Contributor Guide - issue labels](.github/contributing.md#labels))\n\nAlso, please read and follow the project's [Code of Conduct](.github/code_of_conduct.md).\n\n## license\n\nMIT © Bo Lingen / citycide\n\nSee [license](license)\n\n[sqlite3]: https://github.com/mapbox/node-sqlite3\n[sqljs]: https://github.com/kripken/sql.js\n[mongoose]: https://mongoosejs.com/\n[knex]: https://github.com/tgriesser/knex\n[electron]: https://github.com/electron/electron\n[nwjs]: https://github.com/nwjs/nw.js\n[docs]: https://trilogy.js.org\n[typescript]: https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html\n","funding_links":["https://github.com/sponsors/citycide"],"categories":["TypeScript","database","typescript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaltcase%2Ftrilogy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaltcase%2Ftrilogy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaltcase%2Ftrilogy/lists"}