
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
angular-sql-storage
Advanced tools
Manage SQlLite connection and create tables.
##Get Started
bower install angular-sql-storage --save
Include angular-sql-storage.js
(or angular-sql-storage.min.js
) from the dist directory in your index.html
, after including Angular itself.
Add 'sf.sqlStorage'
to your main module's list of dependencies.
When you're done, your setup should look similar to the following:
<!doctype html>
<html ng-app="myApp">
<head>
</head>
<body>
...
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<script src="bower_components/angular-sql-storage/angular-sql-storage.min.js"></script>
...
<script>
var myApp = angular.module('myApp', ['sf.sqlStorage']);
</script>
...
</body>
</html>
##Configuration
###setDatabaseConfig
You can define your name and database version number
The version number let you manage migrations automatically.
The service compares the current version with the latest and runs all updates accordingly
Default: name: database.db
version: 1
myApp.config(function (sqlStorageServiceProvider) {
sqlStorageServiceProvider
.setDatabaseConfig({
name: 'myapp.db',
version: 0.1
});
});
###setDatabaseSchema
You need to define the table definition to create tables
Params:
defaultFields
[Array] - Define fields which appear in all tables
name
[String] - Sql field nametype
[String] - Sql field typeprimayKey
[Boolean] - Add PRIMARY KEY constraint to field.unique
[Boolean] - Add UNIQUE constraint to field.tables
[Object] - Define tables with specific structure
table_name
[String] - Name of tableindexed_fields
[Array] - Add indexed fields to table (structure like defaultFields)myApp.config(function (sqlStorageServiceProvider) {
sqlStorageServiceProvider
.setDatabaseSchema({
defaultFields: [{
name: 'id',
type: 'NVARCHAR(32)',
primayKey: true,
unique: true,
}, {
name: 'payload',
type: 'TEXT',
},
tables: {
users: {
table_name: 'users',
indexed_fields: [{
name: 'age',
type: 'INTEGER',
}],
},
}]
});
});
###setDatabaseInstance
Set the database instance instead of window.openDatabase.
Example, you can use cordova and ngCordova to instantiate your database (Function is invoke by angular $injector.invoke service).
myApp.config(function (sqlStorageServiceProvider) {
sqlStorageServiceProvider
.setDatabaseInstance(databaseInstance);
function databaseInstance($cordovaSQLite) {
return $cordovaSQLite.openDB('myapp.db', 1);
}
});
###addUpdater
You could define migration scripts when you update your database schema. Just need to define verison and script.
You can access to this following instance variable :
this._database
: Database Instance.Params:
version
[Float] - Version which need to run the script.method
[Function] - Method to run by $injector.inoke().myApp.config(function (sqlStorageServiceProvider) {
sqlStorageServiceProvider
.addUpdater({
version: 1.1,
method: updateMethod,
});
function updateMethod($cordovaSQLite) {
var _database = this._database;
var query = 'ALTER TABLE users ADD COLUMN name TEXT';
return $cordovaSQLite.execute(_database, query);
});
});
##API Documentation
##initDatabase
Init instance if you want to update earlier. This method is called by getDatabase too.
Returns: Database Instance
###getDatabase
Just get database instance.
Returns: Database Instance
###initTables
Create Sql tables and run migration if needed
Returns: Database Instance
###deleteDatas Drop all tables (of the database).
###execute
Helpers to execute sql queries.
Returns: Query result
FAQs
Manage SQlLite connection and create tables
We found that angular-sql-storage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.