sqlite-dynamic.js
function( collectionID, criteria, cursor, limit) {
            collectionID = collectionID.toLowerCase();
            var deferred = q.defer();

            // acquire a connection from the pool
            db.getClient().then( function(dbClient) {
                if ( !dbClient ) {
                    throw Error("Failed to acquire sqlite client");
                }

                // do any necessary dynamic schema syncs, if its supported
                schemaSyncer.prepCollection(collectionID)
                .then( function() {
                    return expandIfNecessary(collectionID, schemaSyncer.getTableSchema(collectionID), null, criteria);
                })

                // perform the query
                .then( function() {
                    var sql = sqlAdaptor.createSelectSQL(collectionID, criteria, limit);
                    query(dbClient, sql).then(
                        // success
                        function(r) {
                            var results = dbClient.results();
                            if ( !results || results.rowCount < 1 ) {
                                // if no results, return empty array
                                deferred.resolve([]);
                                return;
                            }

                            var hydratedResults = sqlAdaptor.hydrateResults(results);

                            if ( !cursor ) {
                                deferred.resolve( hydratedResults );
                            } else {
                                var stream = createStreamFrom(hydratedResults);
                                deferred.resolve(stream );
                            }
                        },

                        // error
                        function(e) {
                            jive.logger.error(e.stack);
                            deferred.reject(e);
                        }
                    );
                })
                .fail(function(e){
                    deferred.reject(e);
                })

                // always try to release the client, if it exists
                .finally(function() {
                    if ( dbClient ) {
                        // always try to release the client, if it exists
                        dbClient.release();
                    }
                });
            })
            // failed to acquire the client
            .fail( function(e) {
                deferred.reject(e);
            });

            return deferred.promise;
        }
function( collectionID, criteria, cursor, limit) {
            collectionID = collectionID.toLowerCase();
            var deferred = q.defer();

            // acquire a connection from the pool
            db.getClient().then( function(dbClient) {
                if ( !dbClient ) {
                    throw Error("Failed to acquire sqlite client");
                }

                // do any necessary dynamic schema syncs, if its supported
                schemaSyncer.prepCollection(collectionID)
                .then( function() {
                    return expandIfNecessary(collectionID, schemaSyncer.getTableSchema(collectionID), null, criteria);
                })

                // perform the query
                .then( function() {
                    var sql = sqlAdaptor.createSelectSQL(collectionID, criteria, limit);
                    query(dbClient, sql).then(
                        // success
                        function(r) {
                            var results = dbClient.results();
                            if ( !results || results.rowCount < 1 ) {
                                // if no results, return empty array
                                deferred.resolve([]);
                                return;
                            }

                            var hydratedResults = sqlAdaptor.hydrateResults(results);

                            if ( !cursor ) {
                                deferred.resolve( hydratedResults );
                            } else {
                                var stream = createStreamFrom(hydratedResults);
                                deferred.resolve(stream );
                            }
                        },

                        // error
                        function(e) {
                            jive.logger.error(e.stack);
                            deferred.reject(e);
                        }
                    );
                })
                .fail(function(e){
                    deferred.reject(e);
                })

                // always try to release the client, if it exists
                .finally(function() {
                    if ( dbClient ) {
                        // always try to release the client, if it exists
                        dbClient.release();
                    }
                });
            })
            // failed to acquire the client
            .fail( function(e) {
                deferred.reject(e);
            });

            return deferred.promise;
        }
function ( collectionID , criteria , cursor , limit ) { collectionID = collectionID . toLowerCase ( ) ; var deferred = q . defer ( ) ; // acquire a connection from the pool db . getClient ( ) . then ( function ( dbClient ) { if ( ! dbClient ) { throw Error ( "Failed to acquire sqlite client" ) ; } // do any necessary dynamic schema syncs, if its supported schemaSyncer . prepCollection ( collectionID ) . then ( function ( ) { return expandIfNecessary ( collectionID , schemaSyncer . getTableSchema ( collectionID ) , null , criteria ) ; } ) // perform the query . then ( function ( ) { var sql = sqlAdaptor . createSelectSQL ( collectionID , criteria , limit ) ; query ( dbClient , sql ) . then ( // success function ( r ) { var results = dbClient . results ( ) ; if ( ! results || results . rowCount < 1 ) { // if no results, return empty array deferred . resolve ( [ ] ) ; return ; } var hydratedResults = sqlAdaptor . hydrateResults ( results ) ; if ( ! cursor ) { deferred . resolve ( hydratedResults ) ; } else { var stream = createStreamFrom ( hydratedResults ) ; deferred . resolve ( stream ) ; } } , // error function ( e ) { jive . logger . error ( e . stack ) ; deferred . reject ( e ) ; } ) ; } ) . fail ( function ( e ) { deferred . reject ( e ) ; } ) // always try to release the client, if it exists . finally ( function ( ) { if ( dbClient ) { // always try to release the client, if it exists dbClient . release ( ) ; } } ) ; } ) // failed to acquire the client . fail ( function ( e ) { deferred . reject ( e ) ; } ) ; return deferred . promise ; }
Retrieve a piece of data from a named collection, based on the criteria, return promise
with an array of the results when done.
@param collectionID
@param criteria
@param cursor if true, then returned item is a cursor; otherwise its a concrete collection (array) of items
@param limit optional
Retrieve a piece of data from a named collection based on the criteria return promise with an array of the results when done .