{"id":4613,"url":"https://github.com/jbrodriguez/react-native-android-sqlite","last_synced_at":"2025-10-29T23:20:37.385Z","repository":{"id":57335255,"uuid":"42678179","full_name":"jbrodriguez/react-native-android-sqlite","owner":"jbrodriguez","description":"A react native android wrapper for SQLite","archived":false,"fork":false,"pushed_at":"2015-11-27T09:44:55.000Z","size":15,"stargazers_count":30,"open_issues_count":1,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-02T16:57:15.227Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","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/jbrodriguez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-17T19:47:59.000Z","updated_at":"2024-03-21T10:49:10.000Z","dependencies_parsed_at":"2022-08-31T03:30:46.448Z","dependency_job_id":null,"html_url":"https://github.com/jbrodriguez/react-native-android-sqlite","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/jbrodriguez/react-native-android-sqlite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbrodriguez%2Freact-native-android-sqlite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbrodriguez%2Freact-native-android-sqlite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbrodriguez%2Freact-native-android-sqlite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbrodriguez%2Freact-native-android-sqlite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbrodriguez","download_url":"https://codeload.github.com/jbrodriguez/react-native-android-sqlite/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbrodriguez%2Freact-native-android-sqlite/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268636477,"owners_count":24282094,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-01-05T20:17:17.925Z","updated_at":"2025-10-29T23:20:37.324Z","avatar_url":"https://github.com/jbrodriguez.png","language":"Java","readme":"# React Native Android Sqlite\n\nA react native android wrapper for SQLite\n\n## Rationale\n\nReact Native doesn't have a built-in module to access Sqlite databases, either in iOS or Android.\n\nThis library intends to fill the gap on the Android side.\n\n## Setup\n\n* Install Module\n\n```bash\nnpm install --save-dev react-native-android-sqlite\n```\n\n* `android/settings.gradle`\n\n```gradle\n...\ninclude ':react-native-android-sqlite'\nproject(':react-native-android-sqlite').projectDir = new File(settingsDir, '../node_modules/react-native-android-sqlite')\n```\n\n* `android/app/build.gradle`\n\n```gradle\ndependencies {\n\t...\n\tcompile project(':react-native-android-sqlite')\n}\n```\n\n* register module (in MainActivity.java)\n\n```java\n...\n\nimport io.jbrodriguez.react.*; // \u003c--- import \n\npublic class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {\n\t...\n\t\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        mReactRootView = new ReactRootView(this);\n\n        mReactInstanceManager = ReactInstanceManager.builder()\n                .setApplication(getApplication())\n                .setBundleAssetName(\"index.android.bundle\")\n                .setJSMainModuleName(\"index.android\")\n                .addPackage(new MainReactPackage())\n                .addPackage(new RNSQLiteModule())           // \u003c- add here\n                .setUseDeveloperSupport(BuildConfig.DEBUG)\n                .setInitialLifecycleState(LifecycleState.RESUMED)\n                .build();\n\n        mReactRootView.startReactApplication(mReactInstanceManager, \"YourProject\", null);\n\n        setContentView(mReactRootView);\n    }\t\n}\n```\n\n## Usage\n\nThis library depends on [SQLiteAssetHelper](https://github.com/jgilfelt/android-sqlite-asset-helper).\n\nThe idea is that you `import` your previously created database as an application asset.\n\nSQLiteAssetHelper manages schema definition (create), as well as upgrades.\n\nFor more information refer to [SQLiteAssetHelper's docs](https://github.com/jgilfelt/android-sqlite-asset-helper) and/or check [SQLiteOpenHelper](http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html)\n\nSo, the first step involves copying your sqlite db to the following folder\n\n```\n\u003cYourProject\u003e/android/app/src/main/assets/databases\n```\nSubstitute `\u003cYourProject\u003e` with the folder where your app resides, i.e. AwesomeProject.\n\n\u003e **NOTE**: Originally, I suggested copying the sqlite db to `\u003cReactNativeRootFolder\u003e/node_modules/react-native-android-sqlite/src/main/assets/databases`. Although it works, the db will be erased each time you upgrade this component, so it's better to follow the updated instructions.\n\nHaving done that, you can start interacting with the db, through 4 public functions:\n\n- init\n- query\n- exec\n- close\n\n### Init\nThe database must be initialized before any other call takes place\n\n```js\nvar sqlite = require('react-native-android-sqlite')\n\nvar databaseName = 'app.db'\n\nsqlite.init(databaseName)\n\t.then((_) =\u003e {\n\t\tconsole.log('database initialized.')\n\t}\n)\n\n```\n\n### Exec\npre-requisite: the db must have been initialized\n\n```js\nvar sqlite = require('react-native-android-sqlite')\n\nvar sql = 'INSERT INTO todo(name, completed) VALUES (?, ?)'\nvar params = [\"Create react native android sqlite\", 1]\n\nsqlite.exec(sql, params)\n\t.then((_) =\u003e {\n\t\tconsole.log('row inserted.')\n\t}\n)\n\n```\n\n### Query\npre-requisite: the db must have been initialized\n\n```js\nvar sqlite = require('react-native-android-sqlite')\n\nvar sql = 'SELECT * FROM todo WHERE completed = ?'\nvar params = [1]\n\nsqlite.query(sql, params)\n\t.then((data) =\u003e {\n\t\tconsole.log('retrieved: ', data)\n\t}\n)\n```\n\n### Close\npre-requisite: the db must have been initialized\n\n```js\nsqlite.close()\n    .then((_) =\u003e {\n        console.log('database closed')\n    }\n)\n```\n\n## Known Issues\n* It doesn't return the id for a newly inserted row (maybe create a separate insert function ?)\n* Column types currently supported are Integer and String\n* Additional error handling should be implemented\n* Although I'm using it in my personal projects, it's still an early release. Please do read the [license](https://github.com/jbrodriguz/react-native-android-sqlite/README.md)\n\n## Changes\nPlease submit any PR's you seem fit.\n\n## Credits\n* [React Native](https://facebook.github.io/react-native/) - Awesome software.\n* [Android SQLiteAssetHelper](https://github.com/jgilfelt/android-sqlite-asset-helper) - Simplifying the handling of Android's sqlite interface\n* [React Native Android Badge](https://github.com/jhen0409/react-native-android-badge) - For showing me the light with regards to the gradle build system, as applied to react native\n\n## LICENSE\n\nMIT","funding_links":[],"categories":["Components"],"sub_categories":["System"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbrodriguez%2Freact-native-android-sqlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbrodriguez%2Freact-native-android-sqlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbrodriguez%2Freact-native-android-sqlite/lists"}