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

angular-sql-query

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-sql-query

Make simple query on a SQLite database

  • 2.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

angular-sql-query

NPM version Build status Codacy Badge Codacy Coverage Dependency Status License Downloads

Get Started

bower install angular-sql-query --save

Include angular-sql-query.js (or angular-sql-query.min.js) from the dist directory in your index.html, after including Angular itself.

Add 'sf.sqlQuery' 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-query/angular-sql-query.min.js"></script>
    ...
    <script>
      var myApp = angular.module('myApp', ['sf.sqlQuery']);
    </script>
    ...
</body>
</html>

Configuration

For using this module, your database need to be architectured with these fields:

  • id: Unique key for data.
  • payload: Object data stringify with angular.toJson.

For some extra helpers regarding storage, you can look at this module angular-sql-storage.

Example

var user = new SqlQueryService(name, databaseFn, options);

Params

  • name [String] - Table name
  • database [Function] - Function that return SQL database instance.
  • options [Function] - Query options
    • indexed_fields [Array] - Reference field by adding a column in the table.
function databaseInstance() {
  return $q.when($window.openDatabase('test', '1', 'database', 200000));
}
var user = new SqlQueryService('user', databaseInstance, {
  indexed_fields: ['name'],
});

API Documentation

.getBackUp()

Get data by its id

Params

  • id: Data id

Returns: payload

user.getBackUp(1);

.listBackUp()

All datas

Returns: [Array] payload

user.listBackUp();

.queryBackUp()

All datas corresponding to query.

If field is referenced in options, query can be set directly in SQl Query. Also, a javascript filter is used.

You need to pass an object; the key is the field name and the value is the query value.

  • You can pass an Array to make a IN query.
  • You can pass a Boolean for a 1 or 0 query.
  • You can pass an RegExp to make a LIKE query.

Params:

  • params: [Object] Filter datas

Returns: [Array] payload

user.queryBackUp({
  name: ['Jean', 'Paul'],
  connected: true
});

.saveBackUp()

Save new object data

Params:

  • id: Data key
  • datas: Data object

Returns: [Object] Data saved

user.saveBackUp(1, { name: 'Jean', connected: false });

.updateBackUp()

Update database object

Params:

  • data: Object datas (with id).

Returns: [Object] Data updated

user.updateBackUp({ id: 1, name: 'Paul', connected: false });

.removeBackUp()

Remove database object

Params:

  • id: Object key.

Returns: SQL remove result

user.removeBackUp(1);

.bulkDocsBackUp()

Modify multiple datas

It's possible to update or remove datas with one method called.

You can delete a data by setting an the object key _delete to true.

Params:

  • datas: Array of objects to update.

Returns: SQL update result

user.bulkDocsBackUp([{
  id: 1, name: 'Jean', connected: true,
  id: 2, name: 'Paul', connected: false, _deleted: true
}]);

.execute()

Directly make an SQL query.

Params:

  • query: SQL query.
  • datas: SQL params.

Returns: SQL result

user.execute('SELECT * FROM user WHERE id=?', [1]);

FAQs

Package last updated on 19 Mar 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