{"bugs":{"url":"https://github.com/kriasoft/node-sqlite/issues"},"dist":{"shasum":"0dfc80ac457a6d95314e6ac5552a8bc14a442c02","tarball":"https://registry.npmjs.org/sqlite/-/sqlite-4.0.0-beta.7.tgz","fileCount":26,"integrity":"sha512-gSaRaCLPuNXMw21zoJQGhGMsCHaFpYl+vwxt09EadyEEoNoEuCRpCermqXgcFEl/57EgUSN2a1KX25Zj13SU3Q==","signatures":[{"sig":"MEYCIQCp9slWJfOJpajgHCARFGehUoZjQuPcgjPzX+QaRLIPEwIhAIGcmGS+IQoVFQd2vmaCBvR313nJyJtKQ367GzwoXlpJ","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":76960,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJed9R8CRA9TVsSAnZWagAAaR4P/0jznd6U24HZp0xMIYG7\nXPNA00hvKtJ5o6tm5n8mxuD1RslyjHzUpjxH59S6p3+/flyKuW1jg6MWlEhg\nK+XVqNsXXptlUDE3nSJH3FYPSQxcdRz6pF7iaWzOgnWfTCvar5t9oXlnq9ut\nTeySw0WFJ6EBoXoTBpbpbkkHy4zLu1ZciXGjvMlNnre4UN6bpbrU6Ug2sboT\nB3621c9MBu6KBmVN2jQk0N7oRT3oTGbpZ5b+GLTtC4tc0S0G4zf3tPuL9/5a\nqkDzmJsGAc3p+Z7xrFB7xmzk+0PWGQIO5vGPMH3KFMNKAtg+CbEEGlv9eD+3\nhbK3oNndjQcqhmUe1+lZo2eAZRbue5dGkygFqglP5zTRjqxGdS6mazGEJfZn\n6eKbcz3D7rFU/C2QADiYMv1XL/jwoYHxt4wYVtqjKI+iKvqsWG9ZBMQfX5Ye\nMTYIAKvBBuO53sY4XkRVCy6CtDfVeIGbzOuY6R/+FaaTmgLnwVHLEOvzJgzT\nREDhuQ2FqaUXgrodC21KkQmRBNEbb7tfYohUZuUI3iV7OBjWXBmsUc/ZO4XW\n3b3QdB2yHXIVSefxDXlA/JLQoBP3pbsD7iOs4oA7xeY2mUrYXTFeZnRo+n89\nojYAt/tRN2Y9Syx6xIR8fM/Qg1TS7q25/QGXWJQ2kaAhhwWCZet4MBXvxdLp\nOUr7\r\n=l8wC\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    - [specify typings for a specific database driver](#specify-typings-for-a-specific-database-driver)\n    - [Use generics to get better typings on your rows](#use-generics-to-get-better-typings-on-your-rows)\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.7 --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##### specify typings for a specific database driver\n\n```typescript\nimport sqlite3 from 'sqlite3'\n\n// sqlite3.Database, sqlite3.Statement is the default if no explicit generic is specified\nawait open<sqlite3.Database, sqlite3.Statement>({\n  filename: ':memory'\n})\n```\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##### 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`](docs/globals.md) 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":"37dde904012a80ed5273f0a108731ae5c0d23903","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","build:docs":"typedoc --options typedoc.js --plugin typedoc-plugin-markdown src/ --out docs","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","typedoc":"^0.17.3","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","typedoc-plugin-markdown":"^2.2.17","@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.7_1584911484268_0.9427518644890127","host":"s3://npm-registry-packages"},"_id":"sqlite@4.0.0-beta.7","version":"4.0.0-beta.7"}