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

gcloud-datastore-query-manager

v0.1.4

Published

A query manager for accessing Google Datastore through Node applications

Downloads

14

Readme

gcloud-datastore-query-manager

Code Climate

A query manager for accessing Google Datastore through Node applications. This package is installable by using npm install --save gcloud-datastore-query-manager.

Using the Query Manager

The idea behind the query manager is a first-in-first-out queue. The query manager is essentialy a queue that holds query until they are executed. Once executed, all of the results are return in an array.

As this is a query manager for the gcloud package, you must ensure that you include gcloud wherever you want to use the query manager:

var gcloud = require('gcloud');
var datastore = gcloud.datastore();

Quick Example

Here is how the query manager works, at a very basic level.

Sample datastore:

Kind: Animal

| id/name | species | name | | -------------|:-------------:| -----:| | 871398717813 | lion | Simba | | 234885878798 | tiger | Tony | | 873485798374 | bear | Baloo |

Code
// Synchronous callback
queryManager.add(query, function(error, queryStackLength) {
    if(error)
        throw error;
    else
        console.log('There is now ' + queryStackLength + ' query in the stack.');
});

// Asynchronous callback
queryManager.runAll(function(error, result) {
    if(error)
        throw error;
    else
        console.log(result);
});

Documentation

queryManager

  • addAll - Add an array of queries to the queue
  • addOne - Add one query to the queue
  • getAll - Get an array of all of the queries in the queue
  • getNext - Get the next query in the queue, based on the FIFO model
  • getQueueLength - Get the current length of the queue
  • removeAll - Remove all of the queries from the queue
  • removeNext - Remove the next query in the queue, based on the FIFO model
  • runAll - Run all of the queries in the queue

queryManager

addAll(queries, callback)

A function used to add an array of queries to the queue. Parameters

  • queries - An array of query objects to be added to the queue.
  • callback(error, queueLength) - A callback that returns any errors that occured while inserting the queries to the queue or null, and the length of the queue after the queries were succesfully added (or null if there were errors).

Note that while this function does take a callback function, the operations it performs are synchronous, so the callback is not always necessary.

Example

var animalQuery = datastore.createQuery('Animal');
var movieQuery = datastore.createQuery('Movie');
var queries = [animalQuery, movieQuery];

queryManager.addAll(queries, function(error, queueLength) {
    if(error)
        throw error;
    else
        console.log('Queue length: ' + queueLength);
});

addOne(query, callback)

A function used to add one query to the queue. Parameters

  • query - A query object to be added to the queue.
  • callback(error, queueLength) - A callback that returns any errors that occured while inserting the queries to the queue or null, and the length of the queue after the query was succesfully added (or null if there were errors).

Note that while this function does take a callback function, the operations it performs are synchronous, so the callback is not always necessary.

Example

var animalQuery = datastore.createQuery('Animal');

queryManager.addOne(animalQuery, function(error, queueLength) {
    if(!error) {
        // do something
    }
});

getAll(callback)

A function used to get an array containing all of the queries currently in the queue. Parameters

  • callback(error, queries) - A callback that returns any errors that occured while trying to retrieve the queries stored in the queue or null, and an array containing all of the queries currently in the queue (or null if there were errors).

Note that while this function does take a callback function, the operations it performs are synchronous, so the callback is not always necessary.

Example

queryManager.getAll(function(error, queries) {
    if(!error){
        // do something
    }
});

getNext(callback);

A function used to get the next query to be run in the queue, based on the FIFO model. Parameters

  • callback(error, query) - A callback that returns any errors that occured while trying to retrieve the next query stored in the queue or null, and the next query in the queue (or null if there were errors).

Note that while this function does take a callback function, the operations it performs are synchronous, so the callback is not always necessary.

Example

queryManager.getNext(function(error, query) {
    if(!error){
        // do something
    }
});

getQueueLength(callback)

A function used to get the length of the queue. Parameters

  • callback(error, queueLength) - A callback that returns any errors that occured while trying to retrieve the length of the queue or null, and an integer value representing the number of queries currently in the queue (or null if there were errors).

Note that while this function does take a callback function, the operations it performs are synchronous, so the callback is not always necessary.

Example

queryManager.getQueueLength(function(error, queueLength) {
    if(!error){
        // do something
    }
});

removeAll(callback)

A function used to remove all of the queries from the queue. This function acts in a similar manner to the getAll function, but empties the queue as well as retrieving all of the queries currently in the queue. Parameters

  • callback(error, queries) - A callback that returns any errors that occured while trying to retrieve and remove the queries stored in the queue or null, and an array containing all of the queries currently in the queue (or null if there were errors).

Note that while this function does take a callback function, the operations it performs are synchronous, so the callback is not always necessary.

Example

queryManager.removeAll(function(error, queries) {
    if(!error){
        // do something
    }
});

removeNext(callback)

A function used to the next query from the queue, based on the FIFO model. This function acts in a similar manner to the getNext function, but removes the next query from the queue as well as retrieving it. Parameters

  • callback(error, queries) - A callback that returns any errors that occured while trying to retrieve and remove the next query stored in the queue or null, and the next query in the queue (or null if there were errors).

Note that while this function does take a callback function, the operations it performs are synchronous, so the callback is not always necessary.

Example

queryManager.removeNext(function(error, query) {
    if(!error){
        // do something
    }
});

runAll(callback)

A function used to execute all of the queries from the queue against the Datastore. Parameters

  • callback(error, results) - A callback that returns any errors that occured while trying to execute the queries stored in the queue or null, and an array individuak arrays of results corresponding to each query (or null if there were errors).

Example

queryManager.run(function(error, results) {
    if(!error){
        // do something
    }
});

License

Copyright (c) 2016 Zackery Harley

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.