Code Monkey home page Code Monkey logo

gql's Introduction

GQL

A wrapper to do some easy logging and writing stuff to Google Spreadsheets

Setup

First you must create a doc to write to. Open your Google Drive and sign in.

Next we need to configure the config.json. The config expects the following values to be present:

"auth": {
	"username": "[email protected]",
	"password": "password"
},
"sheet": {
	"name": "name of sheet",
	"id": "optional id",
	"worksheet": {
		"name": "worksheet name",
		"id": "optional id"
	}
}

The sheet.id and sheet.worksheet.id are optional. These will appear in the console when not given, after that you could add them to make the connection faster.

Mapping the sheet

Because Google sheets provides us with a json we can't really work with the data gets remapped. You can ajust the names of the columns in the config.json. A mapping would look like this:

"mapping": {
	"columns":[
		["1", "brand"],
		["2", "model"],
		["3", "customer"],
		["4", "status"],
		["5", "due_date"]
	]
}
How we receive the data
{
	"1": {
	    "1": "motorola",
	    "2": "moto g",
	    "3": "t-mobile-usa",
	    "4": "IN",
	    "5": "31-10-2015"
	}
}
After mapping
{
    "brand": "motorola",
    "model": "moto g",
    "customer": "t-mobile-usa",
    "status": "IN",
    "due_date": "31-10-2015",
    "id": 1
}

Actions

The action have a very simple syntax:

GQL.name_of_action( [id], data, function(){
	//Gets executed when done.
});

Although some action may require an id like:

  • GET
  • UPDATE
  • DESTROY

Because else we wouldn't not know which record to update.

GET

The GET action requires an id or an query to find a array of records to match the query.

// With an ID
GQL.get( id, data, function(){
	//Gets executed when done.
});
// => {} returns an Object

// With an query
// NOTE: Only `===` is supported at this point
GQL.get( 'brand === motorola', data, function(){
	//Gets executed when done.
});
// => [{}, {}, {}] returns an Array of Objects

CREATE

Adds a new record field to the db and updates it with the data that is given.

GQL.create( data, function(){
	//Gets executed when done.
});

UPDATE

Update a record.

GQL.update( id, data, function(){
	//Gets executed when done.
});

DESTROY

Removal is not possible. The record field will be made empty so count as inactive.

GQL.destroy( id, function(){
	//Gets executed when done.
});

DB

If you want to provide al the info to a client side application you can just dump the entire db.

GQL.db() // return entire db

gql's People

Contributors

ramongebben avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.