angular-sql-query
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:
... ... ...
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 = name databaseFn options;
Params
name
[String] - Table namedatabase
[Function] - Function that return SQL database instance.options
[Function] - Query optionsindexed_fields
[Array] - Reference field by adding a column in the table.
{ return $q;}var user = 'user' databaseInstance indexed_fields: 'name';
API Documentation
.getBackUp()
Get data by its id
Params
id
: Data id
Returns: payload
user;
.listBackUp()
All datas
Returns: [Array] payload
user;
.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;
.saveBackUp()
Save new object data
Params:
id
: Data keydatas
: Data object
Returns: [Object] Data saved
user;
.updateBackUp()
Update database object
Params:
data
: Object datas (with id).
Returns: [Object] Data updated
user;
.removeBackUp()
Remove database object
Params:
id
: Object key.
Returns: SQL remove result
user;
.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;
.execute()
Directly make an SQL query.
Params:
query
: SQL query.datas
: SQL params.
Returns: SQL result
user;