{"id":22535545,"url":"https://github.com/juanchinovas/nativescript-sqlite-access","last_synced_at":"2025-04-09T19:08:44.218Z","repository":{"id":57308771,"uuid":"205975572","full_name":"juanchinovas/nativescript-sqlite-access","owner":"juanchinovas","description":"Just a NativeScript plugin to access to sqlite on Android and iOS.","archived":false,"fork":false,"pushed_at":"2022-05-26T03:26:09.000Z","size":136201,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T19:08:38.139Z","etag":null,"topics":["nativescript-plugin","sqlite-android","sqlite-ios"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/nativescript-sqlite-access","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/juanchinovas.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":"2019-09-03T02:46:26.000Z","updated_at":"2023-09-08T17:57:38.000Z","dependencies_parsed_at":"2022-08-29T06:50:36.251Z","dependency_job_id":null,"html_url":"https://github.com/juanchinovas/nativescript-sqlite-access","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanchinovas%2Fnativescript-sqlite-access","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanchinovas%2Fnativescript-sqlite-access/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanchinovas%2Fnativescript-sqlite-access/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanchinovas%2Fnativescript-sqlite-access/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juanchinovas","download_url":"https://codeload.github.com/juanchinovas/nativescript-sqlite-access/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094993,"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":["nativescript-plugin","sqlite-android","sqlite-ios"],"created_at":"2024-12-07T10:07:49.425Z","updated_at":"2025-04-09T19:08:44.176Z","avatar_url":"https://github.com/juanchinovas.png","language":"TypeScript","readme":"# NativeScript sqlite access\n\n[![NPM version][npm-image]][npm-url]\n[![TotalDownloads][total-downloads-image]][npm-url]\n\n[npm-image]:http://img.shields.io/npm/v/nativescript-sqlite-access.svg\n[npm-url]:https://npmjs.org/package/nativescript-sqlite-access\n[total-downloads-image]:http://img.shields.io/npm/dt/nativescript-sqlite-access.svg?label=total%20downloads\n\nJust a NativeScript plugin to access and manage data with sqlite on ![apple](https://cdn3.iconfinder.com/data/icons/picons-social/57/16-apple-32.png) ![android](https://cdn4.iconfinder.com/data/icons/logos-3/228/android-32.png). \n\n## Installation\n\nRun the following command from the root of your project:\n\n```bash\ntns plugin add nativescript-sqlite-access@1.0.81\n```\n`@nativescript/core?`\n\n```bash\ntns plugin add nativescript-sqlite-access@1.2.0\n```\nThe command above automatically installs the necessary files, as well as stores nativescript-sqlite-access as a dependency in your project's package.json file.\n\n## Usage \n\nYou need to import function DbBuilder to create a instance of SqliteAccess class and access to the API of the plugin to manage your app's data.\n\t\n```typescript\nimport { DbBuilder } from 'nativescript-sqlite-access';\n\nexport class HomeViewModel {\n    private db;\n    constructor() {\n        super();\n        // Creating SqliteAccess class instance\n        // Passing the name of the database file\n        this.db = DbBuilder(\"\u003cdatabase_file_name\u003e\");\n    }\n}\n```\n\nThe function DbBuilder receive two parameters the database file name and an optional [**DbCreationOptions**](src/sqlite-access-common.ts#DbCreationOptions) object. If you do not pass the last parameter, a default one will be created, but you cannot set the db version.\n\nSee the full example below in typescript\n\n```typescript\nimport {DbBuilder, IDatabase, DbCreationOptions, ReturnType} from 'nativescript-sqlite-access';\n\nexport class HomeViewModel {\n    private db: IDatabase;\n    constructor() {\n        super();\n        this.db = DbBuilder(\"test.db\", \u003cDbCreationOptions\u003e{\n            version: 1, //Version of the database\n            /*All tables needed*/\n            createTableScriptsFn: ()=\u003e {\n                return ['CREATE TABLE if not exists table_name(_id INTEGER PRIMARY KEY AUTOINCREMENT, column TEXT)'];\n            },\n            /*Drop tables scripts, needed if your will change the tables structure*/\n            dropTableScriptsFn:()=\u003e { \n                return ['DROP TABLE IF EXISTS table_name']\n            },\n            returnType: ReturnType.AS_OBJECT /*(DEFAULT) | ReturnType.AS_ARRAY*/\n        });\n    }\n}\n```\n\n**createTableScriptsFn** and **dropTableScriptsFn** will be executed when database is created or database version is changed to a higher value. Those functions must return an array of string with all the scripts to create or delete the tables used in your app. In case you change a table structure you must change the database version to apply the changes.\n\n### `DbCreationOptions'` properties\n\n| Property | Type | Description |\n| --- | --- | --- |\n|version|`number`| Database version |\n|createTableScriptsFn|`function`| Function that return a `Array` of string with the sql query to create the app's tables |\n|dropTableScriptsFn|`function`| Function that return a `Array` of string with the sql query to drop the app's tables |\n|returnType|`enum`| Indicate the type object returned by the plugin. Possible values `ReturnType.AS_OBJECT` and `ReturnType.AS_ARRAY` |\n\n## API\n```typescript\n/**\n * Insert row into table with the values (key = columns and values = columns value)\n *\n * @param {string} tableName\n * @param {{ [key: string]: unknown; }} values\n *\n * @returns {number}  id inserted\n */\ninsert(tableName: string, values: { [key: string]: unknown }): number;\n```\n```typescript\n/**\n * Update or Insert a row into table. The table has to have at least one primary key column\n *\n * @param {string} tableName\n * @param {{ [key: string]: unknown; }} values\n *\n * @returns {Promise\u003cunknown\u003e}  primary keys affected\n */\nupsert(tableName: string, values: { [key: string]: unknown; }): Promise\u003cunknown\u003e;\n```\n```typescript\n/**\n * Replace row values in the table with the values (key = columns and values = columns value).\n * The table must has a primary column to match with\n *\n * @param {string} tableName\n * @param {{ [key: string]: unknown; }} values\n *\n * @returns {number} affected rows\n */\nreplace(tableName: string, values: { [key: string]: unknown }): number;\n```\n```typescript\n/**\n * Update row values in the table with the values (key = columns and values = columns value) to the matched row.\n *\n * @param {string} tableName\n * @param {{ [key: string]: unknown; }} values\n * @param {string} whereClause\n * @param {Array\u003cunknown\u003e} whereArs\n *\n * @returns {number} affected rows\n */\nupdate(tableName: string, values: { [key: string]: unknown }, whereClause: string, whereArs: Array\u003cunknown\u003e): number;\n```\n```typescript\n/**\n * Delete rows or a row from the table that matches the condition.\n *\n * @param {string} tableName\n * @param {string} whereClause\n * @param {Array\u003cunknown\u003e} whereArs\n *\n * @returns {number} affected rows\n */\ndelete(tableName: string, whereClause?: string, whereArs?: Array\u003cunknown\u003e): number;\n```\n```typescript\n/**\n * Execute a query, return QueryProcessor.\n * @see QueryProcessor for more information.\n *\n * @param {string} sql SQL Query. `SELECT [COLUMNS,] FROM TABLE WHERE column1=? and column2=?`. WHERE clause can be omitted\n * @param {Array\u003cunknown\u003e} conditionParams - optional if there is not WHERE clause in the sql param\n *\n * @returns {QueryProcessor\u003cT\u003e}\n */\nselect\u003cT\u003e(sql: string, conditionParams?: Array\u003cunknown\u003e): QueryProcessor\u003cT\u003e;\n```\n```typescript\n/**\n * Query the given table, return QueryProcessor\n * @see QueryProcessor for more information.\n *\n * @param {string} param.tableName\n * @param {Array\u003cstring\u003e} param.columns\n * @param {string} param.selection\n * @param {Array\u003cunknown\u003e} param.selectionArgs\n * @param {string} param.groupBy\n * @param {string} param.having\n * @param {string} param.orderBy\n * @param {string} param.limit\n *\n * @returns {QueryProcessor\u003cT\u003e}\n */\nquery\u003cT\u003e(param: {\n\ttableName: string, columns?: Array\u003cstring\u003e,\n\tselection?: string, selectionArgs?: Array\u003cunknown\u003e,\n\tgroupBy?: string, having?: string, orderBy?: string, limit?: string\n}): QueryProcessor\u003cT\u003e;\n```\n```typescript\n/**\n* Execute a SQL script and do not return anything\n* @param {string} sql\n*/\nexecSQL(sql: string): void;\n```\n```typescript\n/**\n* Open a transaction\n*/\nbeginTransact(): void;\n```\n```typescript\n/**\n* Commit the transaction\n*/\ncommit(): void;\n```\n```typescript\n/**\n* Rollback a transaction\n*/\nrollback(): void;\n```\n```typescript\n/**\n* Close the database connection\n*/\nclose(): void;\n```\n\n\u003e `select` and `query` function returns a `QueryProcessor` in  v1.1.0\n```typescript\n/**\n * Let you add preprocessing function to each matched row by SQL query.\n * The map and reduce functions are similar to the functions apply to an Array,\n */\nexport declare class QueryProcessor\u003cT\u003e {\n    process\u003cR\u003e(transformer?: ReducerCallback\u003cR\u003e, initialValue?: R): Promise\u003cT\u003e;\n\tprocess\u003cR\u003e(transformer?: MapCallback\u003cR\u003e): Promise\u003cT\u003e;\n    asGenerator(transformer?: MapCallback): Promise\u003cIterableIterator\u003cT\u003e\u003e;\n}\nexport type MapCallback\u003cR\u003e = (row: unknown, index: number) =\u003e R;\nexport type ReducerCallback\u003cR\u003e = ((accumulator: R, row: unknown, index: number) =\u003e R);\n```\n\n### Changes\n\nv1.1.0 `!!Braking changes`\n- `ExtendedPromise` renamed to `QueryProcessor\u003cT\u003e`\n- `map` and `reduce` functions were removed from `QueryProcessor\u003cT\u003e`.\n- `asGenerator` NEW function on `QueryProcessor\u003cT\u003e` allow you to read rows one by one from the db and pass in a row transformer function\n- `process` function allow you to `*transform*` or `*reduce*` the result.\n- Android and iOS minor fixes.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuanchinovas%2Fnativescript-sqlite-access","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuanchinovas%2Fnativescript-sqlite-access","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuanchinovas%2Fnativescript-sqlite-access/lists"}