{"bugs":{"url":"https://github.com/kriasoft/node-sqlite/issues"},"dist":{"shasum":"76996a725b35574770269bb08809e6f02da7ea81","tarball":"https://registry.npmjs.org/sqlite/-/sqlite-4.0.0-beta.6.tgz","fileCount":26,"integrity":"sha512-Pg8zyuHDsYIcgoAfeEQ9mkcgGtT+FALU1WuYyIo39nTPF+tkEXkn7LBseWdtBxTP7p9G4G+/m8JBKK2BxzJC/w==","signatures":[{"sig":"MEQCIDWzqj7gbmnQvaRW6228hs4Z/pzPIB1xeM1fv/sSV1hbAiAh74xWDAJ9tvaouCPzsyyoLhv000WIVv73Msw1juUIcw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":75921,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJed8V8CRA9TVsSAnZWagAAb0QQAI3l1pVBCGDWaCMpMJWX\nqeB1F9wTmtzBo8MUjbCXTqFbYfZ6hKrPLZBk82qMWkE+Z1IHTI3SL5W3njgW\nzv4EgPhtYGloXXUI65unRDNkdoGjG+uVSWqh4vn1JMoFqKEJZZXI+hC4DNGk\nn8fMOmz/BZBWQAK6tG1tYfMZdu7wAWAm6hBqBZY7CM5/dQPHrty5is9zcBtz\nLRIzfS+SKLwTeaOzjDwXpI8ZQCuXguUKTL1q87qITnxWj/i3tE8S8E3d3BnO\nwf/lMJhP5kqIOuidtRW8nQjLzblXa3KdQ/kNUwCQshTf9FMXmv7HpQZfOsO8\nmyXbRZW2LjawEcj8NcYuy/dnSF8e5h+2Him/wDdIA/Gq0AOLLKR9ZPO62KqM\nuyJuK2Ydh1XDvs3cNiTt1rkFk6xW540sn7vHEivULHNLQZ83AIEFcgPuQY2u\nXWpG3EkoQcLY3R0z1CbNfPydeE0MqnQOCVew/i/R4XFweqQSfxpLhsgAYRcQ\n9j7NUQbQhE35Cd82D16rJPnSAwokmuTfe9mnxEK2OBcalY2WPh95rdjvsncs\nv03l3FjvCb6Qxj32NbaAOqjmMaMLiOKfMHOsCKXBodUv8UXj2Bkc1nVp57gl\n3xWXhXyXO1hJ8CpYrFmqNLP6w6Utd2XfgFTVBdPgQKfjeG6wxoe1P+Qf3N8J\nZJZB\r\n=eJOx\r\n-----END PGP SIGNATURE-----\r\n"},"main":"build/index.js","name":"sqlite","types":"build/index.d.ts","author":{"url":"https://www.kriasoft.com","name":"Kriasoft","email":"hello@kriasoft.com"},"readme":"# SQLite Client for Node.js Apps\n\n[![NPM version](http://img.shields.io/npm/v/sqlite.svg?style=flat-square)](https://www.npmjs.com/package/sqlite)\n[![Build Status](http://img.shields.io/travis/kriasoft/node-sqlite/master.svg?style=flat-square)](https://travis-ci.org/kriasoft/node-sqlite)\n[![Online Chat](http://img.shields.io/badge/chat-%23node--sqlite_on_Gitter-blue.svg?style=flat-square)](https://gitter.im/kriasoft/node-sqlite)\n![built with typescript](https://camo.githubusercontent.com/92e9f7b1209bab9e3e9cd8cdf62f072a624da461/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f4275696c74253230576974682f547970655363726970742f626c7565) \n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n> A wrapper library that adds ES6 promises and SQL-based migrations API to\n> [sqlite3](https://github.com/mapbox/node-sqlite3/) ([docs](https://github.com/mapbox/node-sqlite3/wiki)).\n\n**note** v4 of `sqlite` has breaking changes compared to v3! Please see `CHANGELOG.md` for more details.\n\n<!-- TOC -->\n- [Installation](#installation)\n  - [Install `sqlite3`](#install-sqlite3)\n  - [Install `sqlite`](#install-sqlite)\n- [Usage](#usage)\n  - [Opening the database](#opening-the-database)\n    - [Without caching](#without-caching)\n    - [With caching](#with-caching)\n    - [Enable verbose / debug mode](#enable-verbose--debug-mode)\n    - [With a custom driver](#with-a-custom-driver)\n    - [`open` config params](#open-config-params)\n  - [Examples](#examples)\n    - [Creating a table and inserting data](#creating-a-table-and-inserting-data)\n    - [Getting a single row](#getting-a-single-row)\n    - [Getting many rows](#getting-many-rows)\n    - [Inserting rows (part 2)](#inserting-rows-part-2)\n    - [Updating rows](#updating-rows)\n    - [Prepared statement](#prepared-statement)\n    - [`each()`](#each)\n    - [Get the driver instance](#get-the-driver-instance)\n    - [Closing the database](#closing-the-database)\n  - [ES6 tagged template strings](#es6-tagged-template-strings)\n  - [Migrations](#migrations)\n  - [Typescript tricks](#typescript-tricks)\n    - [Use generics to get better typings on your rows](#use-generics-to-get-better-typings-on-your-rows)\n      - [open example](#open-example)\n      - [Get example](#get-example)\n      - [All example](#all-example)\n  - [API Documentation](#api-documentation)\n- [References](#references)\n- [Support](#support)\n- [License](#license)\n\n<!-- TOC END -->\n\n## Installation\n\n### Install `sqlite3`\n\nMost people who use this library will use [sqlite3](https://github.com/mapbox/node-sqlite3/) \nas the database driver. \n\nAny library that conforms to the `sqlite3` ([API](https://github.com/mapbox/node-sqlite3/wiki/API)) \nshould also work.\n\n`$ npm install sqlite3 --save`\n\n### Install `sqlite`\n\n```sh\n# v4 of sqlite is targted for nodejs 10 and on.\n$ npm install sqlite@4.0.0-beta.6 --save\n\n# If you need a legacy version for an older version of nodejs\n# install v3 instead, and look at the v3 branch readme for usage details\n$ npm install sqlite@3 --save\n```\n\n## Usage\n\nThis module has the same API as the original `sqlite3` library ([docs](https://github.com/mapbox/node-sqlite3/wiki/API)),\nexcept that all its API methods return ES6 Promises and do not accept callback arguments (with the exception of `each()`).\n\n### Opening the database\n\n#### Without caching\n\n```typescript\nimport sqlite3 from 'sqlite3'\nimport { open } from 'sqlite'\n\n// this is a top-level await\n(async () => {\n    // open the database\n    const db = await open({\n      filename: '/tmp/database.db',\n      driver: sqlite3.Database\n    })\n})()\n```\nor\n\n```typescript\nimport sqlite3 from 'sqlite3'\nimport { open } from 'sqlite'\n\nopen({\n  filename: '/tmp/database.db',\n  driver: sqlite3.Database\n}).then((db) => {\n  // do your thing\n})\n```\n\n#### With caching\n\nIf you want to enable the [database object cache](https://github.com/mapbox/node-sqlite3/wiki/Caching)\n\n```typescript\nimport sqlite3 from 'sqlite3'\nimport { open } from 'sqlite'\n\n(async () => {\n    const db = await open({\n      filename: '/tmp/database.db',\n      driver: sqlite3.cached.Database\n    })\n})()\n```\n\n#### Enable verbose / debug mode\n\n```typescript\nimport sqlite3 from 'sqlite3'\n\nsqlite3.verbose()\n```\n\n#### With a custom driver\n\nYou can use an alternative library to `sqlite3` as long as it conforms to the `sqlite3` [API](https://github.com/mapbox/node-sqlite3/wiki/API).\n\nFor example, using `sqlite3-offline`:\n\n```typescript\nimport sqlite3Offline from 'sqlite3-offline'\nimport { open } from 'sqlite'\n\n(async () => {\n    const db = await open({\n      filename: '/tmp/database.db',\n      driver: sqlite3Offline.Database\n    })\n})()\n```\n\n#### `open` config params\n\n```typescript\n\n// db is an instance of `sqlite#Database`\n// which is a wrapper around `sqlite3#Database`\nconst db = await open({\n  /**\n   * Valid values are filenames, \":memory:\" for an anonymous in-memory\n   * database and an empty string for an anonymous disk-based database.\n   * Anonymous databases are not persisted and when closing the database\n   * handle, their contents are lost.\n   */\n  filename: string\n\n  /**\n   * One or more of sqlite3.OPEN_READONLY, sqlite3.OPEN_READWRITE and\n   * sqlite3.OPEN_CREATE. The default value is OPEN_READWRITE | OPEN_CREATE.\n   */\n  mode?: OpenDatabaseEnum\n\n  /**\n   * Use an alternative library instead of sqlite3. The interface of the library must\n   * conform to `sqlite3`.\n   *\n   * The default is to use `sqlite3` as the driver.\n   *\n   * @see https://github.com/mapbox/node-sqlite3/wiki/API\n   */\n  driver: any\n})\n```\n\n### Examples\n\n- See the `src/**/__tests__` directory for more example usages\n- See the `docs/` directory for full documentation.\n- Also visit the `sqlite3` library [API docs](https://github.com/mapbox/node-sqlite3/wiki/API)\n\n#### Creating a table and inserting data\n\n```typescript\nawait db.exec('CREATE TABLE tbl (col TEXT)')\nawait db.exec('INSERT INTO tbl VALUES (\"test\")')\n```\n\n#### Getting a single row\n\n```typescript\nconst result = await db.get('SELECT col FROM tbl WHERE col = ?', 'test')\n\n// { col: 'test' }\n```\n\n```typescript\nconst result = await db.get('SELECT col FROM tbl WHERE col = ?', ['test'])\n\n// { col: 'test' }\n```\n\n```typescript\nconst result = await db.get('SELECT col FROM tbl WHERE col = :test', {\n  ':test': 'test'\n})\n\n// { col: 'test' }\n```\n\n#### Getting many rows\n\n```typescript\nconst result = await db.all('SELECT col FROM tbl')\n\n// [{ col: 'test' }]\n```\n\n#### Inserting rows (part 2)\n\n```typescript\nconst result = await db.run(\n  'INSERT INTO tbl (col) VALUES (?)',\n  'foo'\n)\n\n/*\n{\n  // row ID of the inserted row\n  lastId: 1,\n  // instance of `sqlite#Statement`\n  // which is a wrapper around `sqlite3#Statement`\n  stmt: <Statement>\n}\n*/\n```\n\n```typescript\nconst result = await db.run('INSERT INTO tbl(col) VALUES (:col)', {\n  ':col': 'something'\n})\n```\n\n#### Updating rows\n\n```typescript\nconst result = await db.run(\n  'UPDATE tbl SET col = ? WHERE col = ?',\n  'foo',\n  'test'\n)\n\n/*\n{\n  // number of rows changed\n  changes: 1,\n  // instance of `sqlite#Statement`\n  // which is a wrapper around `sqlite3#Statement`\n  stmt: <Statement>\n}\n*/\n```\n\n#### Prepared statement\n\n```typescript\n// stmt is an instance of `sqlite#Statement`\n// which is a wrapper around `sqlite3#Statement`\nconst stmt = await db.prepare('SELECT col FROM tbl WHERE 1 = ? AND 5 = ?5')\nawait stmt.bind({ 1: 1, 5: 5 })\nlet result = await stmt.get()\n// { col: 'some text' }\n```\n\n```typescript\nconst stmt = await db.prepare(\n  'SELECT col FROM tbl WHERE 13 = @thirteen ORDER BY col DESC'\n)\n\nconst result = await stmt.all({ '@thirteen': 13 })\n```\n\n#### `each()`\n\n`each()` is a bit different compared to the other operations.\n\nThe function signature looks like this:\n\n`async each (sql, [...params], callback)`\n\n- `callback(err, row)` is triggered when the database has a row to return\n- The promise resolves when all rows have returned with the number or rows returned.\n\n```typescript\nconst rowsCount = await db.each(\n  'SELECT col FROM tbl WHERE ROWID = ?',\n  [2],\n  (err, row) => {\n    if (err) {\n      throw err\n    }\n\n    // row = { col: 'other thing' }\n  }\n)\n\n// rowsCount = 1\n```\n\n#### Get the driver instance\n\nUseful if you need to call methods that are not supported yet.\n\n```typescript\nconst rawDb = db.getDatabaseInstance()\nconst rawStatement = stmt.getStatementInstance()\n```\n\n#### Closing the database\n\n```typescript\nawait db.close()\n```\n\n### ES6 tagged template strings\n\nThis module is compatible with [sql-template-strings](https://www.npmjs.com/package/sql-template-strings).\n\n```js\nimport SQL from 'sql-template-strings'\n\nconst book = 'harry potter';\nconst author = 'J. K. Rowling';\n\nconst data = await db.all(SQL`SELECT author FROM books WHERE name = ${book} AND author = ${author}`);\n```\n\n### Migrations\n\nThis module comes with a lightweight migrations API that works with [SQL-based migration files](https://github.com/kriasoft/node-sqlite/tree/master/migrations)\n\nWith default configuration, you can create a `migrations/` directory in your project with SQL files,\nand call the `migrate()` method to run the SQL in the directory against the database.\n\nSee this project's `migrations/` folder for examples.\n\n```typescript\nawait db.migrate({    \n    /**\n    * If true, will force the migration API to rollback and re-apply the latest migration over\n    * again each time when Node.js app launches.\n    */\n    force?: boolean\n    /**\n    * Migrations table name. Default is 'migrations'\n    */\n    table?: string\n    /**\n    * Path to the migrations folder. Default is `path.join(process.cwd(), 'migrations')`\n    */\n    migrationsPath?: string\n})\n```\n\n### Typescript tricks\n\n#### Use generics to get better typings on your rows\n\nMost methods allow for the use of [generics](https://www.typescriptlang.org/docs/handbook/generics.html)\nto specify the data type of your returned data. This allows your IDE to perform better autocomplete\nand the typescript compiler to perform better static type analysis.\n\n##### open example\n```typescript\nimport sqlite3 from 'sqlite3'\n\n// sqlite3.Database is the default if no explicit generic is specified\nawait open<sqlite3.Database>({\n  filename: ':memory'\n})\n```\n\n##### Get example\n\n```typescript\n\ninterface Row {\n  col: string\n}\n\n// result will be of type Row, allowing Typescript supported IDEs to autocomplete on the properties!\nconst result = await db.get<Row>('SELECT col FROM tbl WHERE col = ?', 'test')\n```\n\n##### All example\n\n```typescript\ninterface Row {\n  col: string\n}\n\n// Result is an array of rows, you can now have array-autocompletion data\nconst result = await db.all<Row[]>('SELECT col FROM tbl')\n\nresult.each((row) => {\n  // row should have type information now!\n})\n```\n\n### API Documentation\n\nSee the `docs` directory for full documentation.\n\n## References\n\n* [Using SQLite with Node.js for Rapid Prototyping](https://medium.com/@tarkus/node-js-and-sqlite-for-rapid-prototyping-bc9cf1f26f10) on Medium.com\n* [SQLite Documentation](https://www.sqlite.org/docs.html), e.g. [SQL Syntax](https://www.sqlite.org/lang.html), [Data Types](https://www.sqlite.org/datatype3.html) etc. on SQLite.org\n* ES6 tagged [sql-template-strings](https://www.npmjs.com/package/sql-template-strings).\n\n## Support\n\n* Join [#node-sqlite](https://gitter.im/kriasoft/node-sqlite) chat room on Gitter to stay up to date regarding the project\n* Join [#sqlite](https://webchat.freenode.net/?channels=sql,sqlite) IRC chat room on Freenode about general discussion about SQLite\n\n## License\n\nThe MIT License © 2020-present Kriasoft / Theo Gravity. All rights reserved.\n\n---\nMade with ♥ by [Konstantin Tarkus](https://github.com/koistya) ([@koistya](https://twitter.com/koistya)), [Theo Gravity](https://github.com/theogravity) and [contributors](https://github.com/kriasoft/node-sqlite/graphs/contributors)\n","gitHead":"f50d571400ea0389fa041f61c19847fe2a34f698","license":"MIT","scripts":{"toc":"toc-md README.md README.md","lint":"prettier-standard src/**/*.ts && standardx src/**/*.ts","test":"jest","build":"npm run build:clean && npm run compile","debug":"ts-node-dev --inspect -- src/index.ts","compile":"tsc","test:ci":"jest --ci --coverage","add-readme":"git add README.md","test:debug":"node --inspect-brk node_modules/.bin/jest","test:watch":"jest --watch","build:clean":"rm -rf build/*","debug:break":"ts-node-dev --inspect-brk -- src/index.ts","lint-staged":"lint-staged","ts-node-dev":"ts-node-dev","version-bump":"version-bump","changelog:help":"changelog-version","prepare-publish":"npm run changelog:verify && version-bump && npm run changelog:release","changelog:verify":"changelog-version verify","changelog:prepare":"changelog-version prepare","changelog:release":"changelog-version release","test:coverage:watch":"jest --coverage --watch"},"_npmUser":{"name":"theo.gravity","email":"theo@suteki.nu"},"homepage":"https://github.com/kriasoft/node-sqlite#readme","keywords":["sqlite","db","database","sql","migrate","migration","migrations","migrator","seed","seeds","seeder","node","node5","babel","es6","async","promise","promises","api"],"pre-commit":["toc","lint-staged","test:ci","build"],"repository":{"url":"git+https://github.com/kriasoft/node-sqlite.git","type":"git"},"_npmVersion":"6.13.4","description":"SQLite client for Node.js applications with SQL-based migrations API written in Typescript","directories":{},"lint-staged":{"src/**/*.ts":["prettier-standard","git add"]},"maintainers":[{"name":"koistya","email":"hello@tarkus.me"},{"name":"theo.gravity","email":"theo@suteki.nu"}],"_nodeVersion":"10.19.0","contributors":[{"url":"https://twitter.com/koistya","name":"Konstantin Tarkus","email":"hello@tarkus.me"},{"url":"https://theogravity.com","name":"Theo Gravity","email":"theo@suteki.nu"}],"dependencies":{},"eslintConfig":{"rules":{"@typescript-eslint/no-unused-vars":[2,{"args":"none"}]},"parser":"@typescript-eslint/parser","plugins":["@typescript-eslint/eslint-plugin"],"parserOptions":{"sourceType":"module","ecmaVersion":6,"ecmaFeatures":{"modules":true}}},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"25.1.0","eslint":"6.8.0","sqlite3":"^4.1.1","ts-jest":"25.2.1","ts-node":"8.7.0","jest-cli":"25.1.0","standardx":"^5.0.0","pre-commit":"1.2.2","toc-md-alt":"^0.3.2","typescript":"3.8.3","@types/jest":"25.1.4","@types/node":"^13.9.2","lint-staged":"10.0.8","ts-node-dev":"1.0.0-pre.44","@types/sqlite3":"^3.1.6","sqlite3-offline":"^4.2.0","prettier-standard":"16.2.1","jest-junit-reporter":"1.1.0","sql-template-strings":"^2.2.2","@typescript-eslint/parser":"^2.24.0","@theo.gravity/version-bump":"1.2.6","@theo.gravity/changelog-version":"2.1.10","@typescript-eslint/eslint-plugin":"^2.24.0"},"_npmOperationalInternal":{"tmp":"tmp/sqlite_4.0.0-beta.6_1584907643897_0.3857450132747653","host":"s3://npm-registry-packages"},"_id":"sqlite@4.0.0-beta.6","version":"4.0.0-beta.6"}