npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-sql-storage

v1.0.2

Published

Manage SQlLite connection and create tables

Downloads

248

Readme

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