{"id":19680881,"url":"https://github.com/zixiaowang/cordova-angular-sqlcipher","last_synced_at":"2026-03-04T01:17:09.847Z","repository":{"id":58231550,"uuid":"66359466","full_name":"ZixiaoWang/cordova-angular-sqlcipher","owner":"ZixiaoWang","description":"The mid-layer between Cordova Angular project and Cordova Sqlcipher plugin.","archived":false,"fork":false,"pushed_at":"2016-11-04T04:15:02.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T07:11:18.568Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"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/ZixiaoWang.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":"2016-08-23T11:02:38.000Z","updated_at":"2016-10-26T03:17:32.000Z","dependencies_parsed_at":"2022-08-31T03:30:20.016Z","dependency_job_id":null,"html_url":"https://github.com/ZixiaoWang/cordova-angular-sqlcipher","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZixiaoWang%2Fcordova-angular-sqlcipher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZixiaoWang%2Fcordova-angular-sqlcipher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZixiaoWang%2Fcordova-angular-sqlcipher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZixiaoWang%2Fcordova-angular-sqlcipher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZixiaoWang","download_url":"https://codeload.github.com/ZixiaoWang/cordova-angular-sqlcipher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240989495,"owners_count":19889698,"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":[],"created_at":"2024-11-11T18:06:21.607Z","updated_at":"2026-03-04T01:17:09.813Z","avatar_url":"https://github.com/ZixiaoWang.png","language":null,"readme":"# cordova-angular-sqlcipher\nThe mid-layer between Cordova Angular project and Cordova Sqlcipher plugin.\n\n### HOW TO INSTALL?\n1. Import angular js to your project, if you've already had angular js in your project, ignore this step.\n2. Install [liteHelpers/Cordova-sqlcipher-adapter](https://github.com/litehelpers/Cordova-sqlcipher-adapter) by entering cmd \n  \u003ccode\u003ecordova plugin add https://github.com/litehelpers/Cordova-sqlcipher-adapter\u003c/code\u003e\n3. Bower install angular-sqlcipher by entering cmd \u003ccode\u003ebower install angular-sqlcipher\u003c/code\u003e \n\n------\n### How to use it?  \n1. Add following \u003ccode\u003escript\u003c/code\u003e tag into your html.\n```html\n\u003cscript type=\"text/javascript\" src=\"your-path/angular-sqlcipher.min.js\"\u003e\u003c/script\u003e\n```\n2. Add \u003ccode\u003engSqlcipher\u003c/code\u003e to your Angular dependencies.  \n```javascript\nvar app = angular.module('myApp', ['ngSqlcipher']);\n```\n3. Inject service \u003ccode\u003e$sqlcipher\u003c/code\u003e to the function which requires it.\n```javascript\napp.\n    controller('appCtrl', ['$scope', '$sqlcipher', function($scope, $sqlcipher){\n        // ... your code here\n    }];\n```\n\n------\n### Config and create database  \nThe $sqlcipher services is the object returned after creating database. In original command  \n```javascript \nvar db = openDatabase('db.name', 'db.version', 'db.description', 'db.size', callbackFn);\n```\n\u003ccode\u003edb\u003c/code\u003e is the object after the database \u003ccode\u003edb.name\u003c/code\u003e was created. And this operation has to\nbe configured in angular.config.\n```javascript\napp\n    .config(['sqlcipherConfigProvider', function(sqlcipherConfigProvider){\n        var options = {\n            name:'my.db',\n            password:'admin',\n            location:'default',\n            iosDatabaseLocation:'defalult'\n        };\n        sqlcipherConfigProvider.open(options, callbackFn);\n    }])\n```\n\n------\n### APIs  \n| functions |  |\n|----|----|\n| [trans(_fn_)](#trans) | equivalent to \u003ccode\u003edb.transaction(fn)\u003c/code\u003e |\n|[readTrans(_fn_)](#readTrans)| equivalent to \u003ccode\u003edb.readTransaction(fn)\u003c/code\u003e|\n|[createTable(_table_name_, _options_)](#createTable)|_table_name_ : String, \u003cbr\u003e _options_ : Array, String|\n|[dropTable(_table_name_)](#dropTable)| _table_name_ : String |\n|[truncate(_table_name_)](#truncate)| _table_name_ : String \u003cbr\u003e NOTE: this will erase all the data in table|\n|[select(_table_name_, _col_names_, _conditions_)](#select)|_table_name_ : String \u003cbr\u003e _col_name_ : Array \u003cbr\u003e _conditions_ : Object|\n|[selectAll(_table_name_)](#selectAll)|_table_name_ : String \u003cbr\u003e This function is equivalent to \u003cBr\u003e \u003ccode\u003eSELECT * FROM table_name\u003c/code\u003e|\n|[insert(_table_name_, _dataSet_)](#insert)|_table_name_ : String \u003cbr\u003e _dataSet_ : Array|\n|[renameTable(_table_name_, _new_table_name_)](#renameTable)|_table_name_ : String \u003cbr\u003e _new_table_name_ : String|\n|[addColumns(_table_name_, _cols_)](#addColumns)|_table_name_ : String \u003cbr\u003e _cols_ : String or Array|\n|[update(_table_name_, _options_, _conditions_)](#update)|_table_name_ : String \u003cbr\u003e _options_ : Object \u003cbr\u003e _conditions_ : Object |\n\n### Examples   \n###### \u003ca id=\"trans\"\u003e\u003c/a\u003etrans(_fn_)  \n\u003ccode\u003e$sqlcipher.trans(_fn_).then(_successCallbackFn_).catch(_errorCallbackFn_);\u003c/code\u003e\n```javascript\n$sqlcipher\n    .trans(function(tx){\n        tx.executeSql('SELECT * FROM table_name')   // Where statements were executed.\n    }).then(function(result){\n        console.log(result.rows.item(0));           // {name:'Jacky', age:25}\n    }).catch(function(err){\n        console.log(err);\n    })\n```  \n\n###### \u003ca id=\"readTrans\"\u003e\u003c/a\u003ereadTrans(_fn_)  \nNormally, read-transaction are recommended for \u003ccode\u003eSELECT\u003c/code\u003e execution.\n\u003ccode\u003e$sqlcipher.readTrans(_fn_).then(_successCallbackFn_).catch(_errorCallbackFn_);\u003c/code\u003e\n```javascript\n$sqlcipher\n    .readTrans(function(tx){\n        tx.executeSql('SELECT * FROM table_name')   // Where statements were executed.\n    }).then(function(result){\n        console.log(result.rows.item(0));           // {name:'Jacky', age:25}\n    }).catch(function(err){\n        console.log(err);\n    })\n```\n\n###### \u003ca id=\"createTable\"\u003e\u003c/a\u003ecreateTable(_table_name_, _options_)\n\u003ccode\u003eoptions\u003c/code\u003e can be Array or String.  \n\u003ccode\u003e$sqlcipher.createTable(_table_name_, _options_).then(_successCallbackFn_).catch(_errorCallbackFn_);\u003c/code\u003e\n```javascript\n// recommended\nvar options = [\n    {name:'id', type:'INTEGER', primary:true, autoIncrement:true},\n    {name:'name', type:'TEXT', notNull:true},\n    {name:'age', type:'INTEGER'}\n];\n// or\nvar options = ['id INTEGER PRIMARY KEY AUTOINCREMENT', 'name TEXT NOT NULL', 'age INTEGER'];\n// or\nvar options = 'id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, age INTEGER';\n$sqlcipher\n    .createTable('my_table', options)\n    .then((msg) =\u003e {console.log(msg);})     // SQLResultSet {rows: SQLResultSetRowList, insertId: 0, rowsAffected: 0}\n    .catch((err) =\u003e {console.log(err); });  // error messages.\n```  \n\n###### \u003ca id=\"dropTable\"\u003e\u003c/a\u003edropTable(_table_name_)\n```javascript\n$ngSqlcipher.dropTable('table_name'); // table will be deleted\n```  \n  \n###### \u003ca id=\"truncate\"\u003e\u003c/a\u003etruncate(_table_name_)\n```javascript\n$ngSqlcipher.truncate('table_name');  // table will be erased.\n```  \n\n###### \u003ca id=\"select\"\u003e\u003c/a\u003eselect(_table_name_, _col_names_, _conditions_)  \n\u003ccode\u003eselect(_table_name_, _col_names_, _conditions_).then(_successCallbackFn_).catch(_errorCallbackFn_)\u003c/code\u003e\n```javascript\nvar conditions = {\n    where:'id\u003c10\u0026\u0026name==\"Jacky\"'\n    // groupby:'name',\n    // having:'key_word',\n    // orderby:'key_word',\n    // sort:'key_word'\n}\n$sqlcipher\n    .select('myTable', ['age'], conditions)\n    .then( (res) =\u003e console.log(res.rows.item(0) )  // return {age:25}\n    .catch( (err) =\u003e console.log(err) );            // err\n```\n\n###### \u003ca id=\"selectAll\"\u003e\u003c/a\u003eselectAll(_table_name_)\n\u003ccode\u003eselectAll(_table_name_).then(_successCallbackFn_).catch(_errorCallbackFn_)\u003c/code\u003e\n```javascript\n$sqlcipher\n    .selectAll('myTable')\n    .then( (res) =\u003e console.log(res.rows.item(0) )  // return {name:'Jacky', age:25}\n    .catch( (err) =\u003e console.log(err) );            // err\n```  \n\n###### \u003ca id=\"insert\"\u003e\u003c/a\u003einsert(_table_name_, _dataSet_)\n\u003ccode\u003einsert('table_name', dataSet).then(_successCallbackFn_).catch(_errorCallbackFn_)\u003c/code\u003e\n```javascript\nvar dataSet = [\n    {name:'Rynn', age:30},\n    {name:'Amy', age:22}\n]\n$sqlcipher \n    .insert('myTable', dataSet)\n    .then((res)=\u003e{console.log(res)})                // d {$$state: Object} NOTE: this is a promise type\n    .catch( (err) =\u003e console.log(err) );            // err\n```\n\n###### \u003ca id=\"renameTable\"\u003e\u003c/a\u003erenameTable(_table_name_, _new_table_name_)\n\u003ccode\u003erenameTable('myTable', 'myNewTable')\u003c/code\u003e\n```javascript\n$sqlcipher.renameTable('myTable', 'myNewTable');    // table will be renamed;\n```\n\n###### \u003ca id=\"addColumns\"\u003e\u003c/a\u003eaddColumns(_table_name_, _cols_)\n\u003ccode\u003eaddColumns('myTable', _cols_)\u003c/code\u003e\n```javascript\nvar cols = [\n    {name:'gender', type:'TEXT'},\n    {name:'title', type:'TEXT'}\n];\n/* or */ cols = ['gender TEXT', 'title TEXT'];\n/* or */ cols = 'gender TEXT, title TEXT';\n$sqlcipher\n    .addColumns('myTable', cols)\n    .then((res) =\u003e console.log(res))                // d {$$state: Object} NOTE: this is a promise type\n    .catch((err) =\u003e console.log(err))               // err\n```\n\n###### \u003ca id=\"update\"\u003e\u003c/a\u003eupdate(_table_name_, _options_, _conditions_)\n\u003ccode\u003eupdate(_table_name_, _options_, _conditions_)\u003c/code\u003e\n```javascript\nvar options = {\n    age:23,\n    title:'Software Developer' // or Ingeter, function\n}\nvar conditions = {\n    where:'id\u003c10' // where only\n}\n$sqlcipher\n    .update('myTable', options, conditions)\n    .then((res) =\u003e console.log(res))\n    .catch((res) =\u003e console.log(res))\n```\n\n------\n### What if I do not want to use those APIs?  \nFor this situation, use following methods:  \n\u003ccode\u003e var db = $sqlcipher.core; \u003c/code\u003e  \n\u003ccode\u003edb\u003c/code\u003e is the oringinal object returned by openDatabase() function.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzixiaowang%2Fcordova-angular-sqlcipher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzixiaowang%2Fcordova-angular-sqlcipher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzixiaowang%2Fcordova-angular-sqlcipher/lists"}