# @drumtj/gdb

> db query on google sheet

Latest version **1.1.1** (published 2020-03-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @drumtj/gdb
pnpm add @drumtj/gdb
yarn add @drumtj/gdb
bun add @drumtj/gdb
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2020-03-24 |
| First published | 2020-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 260.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | tj |
| Maintainers | drumtj |
| Keywords | db, google sheet, query |

## Links

- npm: https://www.npmjs.com/package/@drumtj/gdb
- Repository: https://github.com/drumtj/gdb
- Issues: https://github.com/drumtj/gdb/issues
- npm.io page: https://npm.io/package/@drumtj/gdb

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2020-03-24
- 1.1.0 — 2020-03-24
- 1.0.18 — 2020-03-24
- 1.0.17 — 2020-03-24
- 1.0.16 — 2020-03-24
- 1.0.15 — 2020-03-24
- 1.0.14 — 2020-03-23
- 1.0.13 — 2020-03-23
- 1.0.12 — 2020-03-23
- 1.0.11 — 2020-03-23
- 1.0.10 — 2020-03-23
- 1.0.9 — 2020-03-23
- 1.0.8 — 2020-03-23
- 1.0.7 — 2020-03-23
- 1.0.6 — 2020-03-23
- … 4 more at https://npm.io/package/@drumtj/gdb/versions

## README

# GDB

[![npm version](https://img.shields.io/npm/v/@drumtj/gdb.svg?style=flat)](https://www.npmjs.com/package/@drumtj/gdb)
[![license](https://img.shields.io/npm/l/@drumtj/gdb.svg)](#)

Library for using Google Sheets as a database


## Installing

Using npm:

```bash
$ npm install @drumtj/gdb
```

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

CommonJS
```js
import GDB from '@drumtj/gdb';
```
```js
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
```js
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
```ts
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
```sh
git clone https://github.com/drumtj/gdb.git
cd gdb
npm install
npm start
```

## License

MIT

---
_Source: https://npm.io/package/@drumtj/gdb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
