{"id":4695,"url":"https://github.com/craftzdog/react-native-sqlite-2","last_synced_at":"2025-05-16T12:06:39.359Z","repository":{"id":18899831,"uuid":"85531416","full_name":"craftzdog/react-native-sqlite-2","owner":"craftzdog","description":"SQLite3 Native Plugin for React Native for iOS, Android, Windows and macOS.","archived":false,"fork":false,"pushed_at":"2023-03-07T06:00:09.000Z","size":2123,"stargazers_count":369,"open_issues_count":33,"forks_count":87,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-04-26T03:36:56.165Z","etag":null,"topics":["pouchdb","react-native","sqlite","sqlite3"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/craftzdog.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-03-20T03:26:12.000Z","updated_at":"2024-04-19T01:38:04.000Z","dependencies_parsed_at":"2024-01-09T07:42:54.364Z","dependency_job_id":"fb26922d-71e1-4c75-abc8-aa9cc8da040c","html_url":"https://github.com/craftzdog/react-native-sqlite-2","commit_stats":{"total_commits":178,"total_committers":28,"mean_commits":6.357142857142857,"dds":0.4943820224719101,"last_synced_commit":"64ec364c7eb5b92fc3594c9b141c190b8c7be1d3"},"previous_names":["noradaiko/react-native-sqlite-2"],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftzdog%2Freact-native-sqlite-2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftzdog%2Freact-native-sqlite-2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftzdog%2Freact-native-sqlite-2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftzdog%2Freact-native-sqlite-2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/craftzdog","download_url":"https://codeload.github.com/craftzdog/react-native-sqlite-2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247987284,"owners_count":21028895,"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":["pouchdb","react-native","sqlite","sqlite3"],"created_at":"2024-01-05T20:17:20.524Z","updated_at":"2025-04-09T06:09:27.658Z","avatar_url":"https://github.com/craftzdog.png","language":"TypeScript","funding_links":[],"categories":["Components","sqlite"],"sub_categories":["Storage"],"readme":"# \u003cimg src=\"./docs/cover.png\" alt=\"React Native SQLite 2\" aria-label=\"React Native SQLite 2\" /\u003e\n\nSQLite3 Native Plugin for React Native for Android, iOS, Windows and macOS.\nThis plugin provides a [WebSQL](http://www.w3.org/TR/webdatabase/)-compatible API to store data in a react native app, by using a SQLite database on the native side.\n\nInspired by fantastic work done by [Nolan Lawson](https://github.com/nolanlawson/cordova-plugin-sqlite-2).\nIt should be a drop-in replacement for [react-native-sqlite-storage](https://github.com/andpor/react-native-sqlite-storage).\nIt works pretty well with [PouchDB](https://github.com/stockulus/pouchdb-react-native) on React Native app.\n\n#### Used by\n\n\u003cimg src=\"docs/firefox-logo.png\" width=\"40\" /\u003e [mozilla / notes](https://github.com/mozilla/notes)\n\u003cimg src=\"docs/inkdrop-logo.png\" width=\"40\" /\u003e [Inkdrop](https://www.inkdrop.app/)\n\n## Why?\n\nThe reason for this plugin is that `react-native-sqlite-storage` has some problems when used with PouchDB:\n\n- It [can't store string data with `\\u0000`](https://github.com/andpor/react-native-sqlite-storage/issues/107) due to [the react native problem](https://github.com/facebook/react-native/issues/12731).\n  - PouchDB heavily uses the Null character in the document IDs for building index, so it won't work well.\n- It's unstable for storing PouchDB's attachments: [#6037](https://github.com/pouchdb/pouchdb/issues/6037).\n\nThis plugin solves these problems.\n\n### Newer SQLite3 on Android\n\nEven the latest version of Android is several versions behind the latest version of SQLite, whereas iOS has newer version.\nReact Native SQLite 2 uses [sqlite-android](https://github.com/requery/sqlite-android) which allows you to use the latest version of it with new SQLite features enabled:\n\n- [JSON1 extension](https://www.sqlite.org/json1.html)\n- [Common Table expressions](https://www.sqlite.org/lang_with.html)\n- [Indexes on expressions](https://www.sqlite.org/expridx.html)\n- [FTS5 extension](https://sqlite.org/fts5.html)\n\n## Getting started\n\nAdd react-native-sqlite-2 to your dependencies:\n\n```shell\n$ npm install react-native-sqlite-2 --save\n```\n\n### Link native dependencies\n\nFrom react-native 0.60 autolinking will take care of the link step but don't forget to run `pod install`.\n\n```shell\n$ react-native link react-native-sqlite-2\n```\n\n#### iOS/macOS\n\nIf using cocoapods in the `ios/` directory run\n\n```shell\n$ pod install\n```\n\n#### Android\n\nPlease make sure AndroidX is enabled in your project by editing `android/gradle.properties` and adding 2 lines:\n\n```\nandroid.useAndroidX=true\nandroid.enableJetifier=true\n```\n\n## Usage\n\n```javascript\nimport SQLite from 'react-native-sqlite-2'\n\nconst db = SQLite.openDatabase('test.db', '1.0', '', 1)\ndb.transaction(function(txn) {\n  txn.executeSql('DROP TABLE IF EXISTS Users', [])\n  txn.executeSql(\n    'CREATE TABLE IF NOT EXISTS Users(user_id INTEGER PRIMARY KEY NOT NULL, name VARCHAR(30))',\n    []\n  )\n  txn.executeSql('INSERT INTO Users (name) VALUES (:name)', ['nora'])\n  txn.executeSql('INSERT INTO Users (name) VALUES (:name)', ['takuya'])\n  txn.executeSql('SELECT * FROM `users`', [], function(tx, res) {\n    for (let i = 0; i \u003c res.rows.length; ++i) {\n      console.log('item:', res.rows.item(i))\n    }\n  })\n})\n```\n\nSee [an example project](/example/) for more detail.\n\n### Using with PouchDB\n\nIt can be used with [pouchdb-adapter-react-native-sqlite](https://github.com/craftzdog/pouchdb-adapter-react-native-sqlite).\n\n```javascript\nimport PouchDB from 'pouchdb-react-native'\nimport SQLite from 'react-native-sqlite-2'\nimport SQLiteAdapterFactory from 'pouchdb-adapter-react-native-sqlite'\n\nconst SQLiteAdapter = SQLiteAdapterFactory(SQLite)\nPouchDB.plugin(SQLiteAdapter)\nvar db = new PouchDB('mydb', { adapter: 'react-native-sqlite' })\n```\n\n### Foreign key support\n\nAs part of database initialization, this library will enable foreign key support automatically on both iOS \u0026 Android. Thus, any tables that define foreign key constraints will have them enforced whether or not foreign key support is explicitly enabled/disabled by PRAGMA statements sent via SQL.\n\n## Changelog\n\nSee [CHANGELOG.md](./CHANGELOG.md)\n\n## Contributing\n\nSee [CONTRIBUTING.md](./CONTRIBUTING.md)\n\n## Original Cordova SQLite Bindings from Nolan Lawson\n\nhttps://github.com/nolanlawson/cordova-plugin-sqlite-2\n\nThe issues and limitations for the actual SQLite can be found on this site.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraftzdog%2Freact-native-sqlite-2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcraftzdog%2Freact-native-sqlite-2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraftzdog%2Freact-native-sqlite-2/lists"}