Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular-sql-storage

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-sql-storage

Manage SQlLite connection and create tables

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
decreased by-84.93%
Maintainers
1
Weekly downloads
 
Created
Source

angular-sql-storage

Manage SQlLite connection and create tables.

NPM version Build status Test coverage Dependency Status License Downloads

##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 name
    • type [String] - Sql field type
    • primayKey [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 table
    • indexed_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

Package last updated on 16 Jun 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc