= EdenMobile Database = [[TOC]] == emResources Service == Access to user data is provided by the {{{emResources}}} service: To use the service, it must be included in the controller dependencies: {{{#!js EdenMobile.controller("MyController", [ '$scope', '$stateParams', 'emResources', function($scope, $stateParams, emResources) { emResources.open(resourceName).then(function(resource) { // Do something with the resource }); } ]); }}} See also: [wiki:DeveloperGuidelines/EdenMobile/Database/Resources EdenMobile Resources API] {{{emResources}}} uses the {{{emDB}}} service to access the database. == emDB Service == EdenMobile provides the {{{emDB}}} service to access the database. To use the service, it must be included in the controller dependencies: {{{ #!js EdenMobile.controller("MyController", [ '$scope', '$stateParams', 'emDB', function($scope, $stateParams, emDB) { // controller code goes here } ]); }}} {{{emDB}}} automatically creates the database and tables when it is initialized for the first time. == API == {{{ #!div class="important" style="border: 2pt solid; text-align: center; width:80%" Remember that '''all database transactions are asynchronous'''! Callback functions may therefore need to perform a {{{$scope.$apply}}} to trigger a digest cycle explicitly. }}} === table === The '''table''' API provides fundamental methods to access data in database tables, examples: {{{#!js // Instantiate the API with the table name table = $emdb.table("mytable"); // Insert records into the table table.insert({ // The data to insert 'name': 'Example', 'number': 4 }, function(recordID) { // Callback function after successful insert }); // Select records from the table - general pattern var fields = ['id', 'name'], query = 'number > 3'; table.select(fields, query, function(result) { var rows = result.rows, record; for (var i=0, len=rows.length; i