1.1.1 • Published 5 years ago

@drumtj/gdb v1.1.1

Weekly downloads
20
License
MIT
Repository
github
Last release
5 years ago

GDB

npm version license

Library for using Google Sheets as a database

Installing

Using npm:

$ npm install @drumtj/gdb

Using cdn:

<script src="https://unpkg.com/@drumtj/gdb@1.1.1/dist/gdb.js"></script>

CommonJS

import GDB from '@drumtj/gdb';
const GDB = require('@drumtj/gdb');

Caution

Only Google Sheet with shared link is working.

How To

query language syntax document

https://developers.google.com/chart/interactive/docs/querylanguage

test google sheet

https://docs.google.com/spreadsheets/d/1Ha9S6ZjGobRoIzzIHJeeUKcLBYqooRZ7V7PMCEN3qKg/edit#gid=0

code

var db = new GDB("1Ha9S6ZjGobRoIzzIHJeeUKcLBYqooRZ7V7PMCEN3qKg");
db.query({
  ////// input sheetname or sheetid(gid)
  sheetName: "data",
  //gid: 122345642, //sheetid

  ////// sql query
  // sql: "SELECT *"
  sql : "SELECT B, C, D, E where D is not null"
}).then(function(data){
  console.log("data", data);
  console.log('findColumnKeyByName("author") =>', data.findColumnKeyByName("author"));
  console.log('findColumnKeyByName("author, email") =>', data.findColumnKeyByName("author, email"));
  console.log('findColumnKeyByName(["author", "email"]) =>', data.findColumnKeyByName(["author", "email"]));
  console.log('getColumn("E") =>', data.getColumn("E"));
  console.log('getColumn(findColumnKeyByName("author, email")) =>', data.getColumn(data.findColumnKeyByName("author, email")));
  console.log('getRow(0) =>', data.getRow(0));
  console.log('getHeader() =>', data.getHeader());
});

Interface

class GDB {
  interface QueryOption {
  	sheetName?: string;
  	gid? 			: string | number;
  	sql				: string;
  };

  interface GDBRowData {
    [column: string]: string|number;
  }

  constructor(sheetID:string=null, header:number=2);
  setId(sheetID:string);
  getId();
  query(option:QueryOption):Promise<GDBRowData[]>;
}

data.findColumnKeyByName(columnName:string|string[]):string|string[];
data.getColumn(columnKey:string):any[]|any[][];
data.getRow(index:number):Object;
data.getHeader():any[];

Test

git clone https://github.com/drumtj/gdb.git
cd gdb
npm install
npm start

License

MIT

1.1.1

5 years ago

1.1.0

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago