All Projects â†’ franciscop â†’ Drive Db

franciscop / Drive Db

Licence: mit
📊 Use Google Drive spreadsheets as a simple database

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Drive Db

Seatable
SeaTable: easy like a spreadsheet, powerful like a database
Stars: ✭ 231 (-70.46%)
Mutual labels:  spreadsheet, database
Googlesheets
Google Spreadsheets R API
Stars: ✭ 771 (-1.41%)
Mutual labels:  spreadsheet, google-drive
Googlesheets4
Google Spreadsheets R API (reboot of the googlesheets package)
Stars: ✭ 232 (-70.33%)
Mutual labels:  spreadsheet, google-drive
Jaydebeapi
JayDeBeApi module allows you to connect from Python code to databases using Java JDBC. It provides a Python DB-API v2.0 to that database.
Stars: ✭ 247 (-68.41%)
Mutual labels:  database, db
Qb
The database toolkit for go
Stars: ✭ 524 (-32.99%)
Mutual labels:  database, db
Gsheets Db Api
A Python DB-API and SQLAlchemy dialect to Google Spreasheets
Stars: ✭ 122 (-84.4%)
Mutual labels:  spreadsheet, db
Crate
CrateDB is a distributed SQL database that makes it simple to store and analyze massive amounts of data in real-time.
Stars: ✭ 3,254 (+316.11%)
Mutual labels:  database, db
Sqldb Logger
A logger for Go SQL database driver without modify existing *sql.DB stdlib usage.
Stars: ✭ 160 (-79.54%)
Mutual labels:  database, db
Unrealm
Unrealm is an extension on RealmCocoa, which enables Swift native types to be saved in Realm.
Stars: ✭ 425 (-45.65%)
Mutual labels:  database, db
Mongo Seeding
The ultimate solution for populating your MongoDB database.
Stars: ✭ 375 (-52.05%)
Mutual labels:  database, db
Tiedot
A rudimentary implementation of a basic document (NoSQL) database in Go
Stars: ✭ 2,643 (+237.98%)
Mutual labels:  database, db
Bitcask
🔑A high performance Key/Value store written in Go with a predictable read/write performance and high throughput. Uses a Bitcask on-disk layout (LSM+WAL) similar to Riak.
Stars: ✭ 654 (-16.37%)
Mutual labels:  database, db
Db
Data access layer for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.
Stars: ✭ 2,832 (+262.15%)
Mutual labels:  database, db
Airrecord
Ruby wrapper for Airtable, your personal database
Stars: ✭ 193 (-75.32%)
Mutual labels:  spreadsheet, database
Vuerd
ERD Editor
Stars: ✭ 208 (-73.4%)
Mutual labels:  database, db
Lazer Database
PHP flat file database to store data with JSON
Stars: ✭ 254 (-67.52%)
Mutual labels:  database, db
Node Mysql Utilities
Query builder for node-mysql with introspection, etc.
Stars: ✭ 98 (-87.47%)
Mutual labels:  database, db
Laravel Db Profiler
Database Profiler for Laravel Web and Console Applications.
Stars: ✭ 141 (-81.97%)
Mutual labels:  database, db
Bitraft
🎉A Bitcask Distributed Key/Value store using Raft for consensus with a Redis compatible API written in Go.
Stars: ✭ 348 (-55.5%)
Mutual labels:  database, db
Node Sqlite
SQLite client for Node.js applications with SQL-based migrations API written in Typescript
Stars: ✭ 642 (-17.9%)
Mutual labels:  database, db

drive-db npm install drive-db test badge demo

Use Google Drive spreadsheets as a simple database for Node.js and the browser. Perfect for collaboration with multiple people editing the same spreadsheet:

import drive from 'drive-db';

// Load the data from the Drive Spreadsheet
(async () => {
  const db = await drive("1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k");
  console.log(db);
})();
id firstname lastname age city
1 John Smith 34 San Francisco
2 Merry Johnson 19 Tokyo
3 Peter Williams 45 London

Becomes an array of objects with the corresponding keys:

[
  {
    "id": "1",
    "firstname": "John",
    "lastname": "Smith",
    "age": "34",
    "city": "San Francisco"
  },
  {
    "id": "2",
    "firstname": "Merry",
    "lastname": "Johnson",
    "age": "19",
    "city": "Tokyo"
  },
  ...
]

Getting Started

Create the Google Drive spreadsheet and publish it:

Now you can either add the CDN <script> or use a bundler. For the CDN:

<script src="https://cdn.jsdelivr.net/npm/drive-db"></script>

Otherwise install drive-db in your project:

npm install drive-db

And then load the spreadsheet into your project:

// Include the module and tell it which spreadsheet to use
const drive = require("drive-db");

// Create an async context to be able to call `await`
(async () => {
  // Load the data from the Drive Spreadsheet
  const db = await drive("1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k");

  console.log(db);
})();

The table has to have a structure similar to this, where the first row are the alphanumeric field names:

id firstname lastname age city
1 John Smith 34 San Francisco
2 Merry Johnson 19 Tokyo
3 Peter Williams 45 London

See this document as an example. Please do not request access to edit it.

API

You import a single default export depending on your configuration:

// For ES7 modules
import drive from "drive-db";

// For common.js imports
const drive = require("drive-db");

To retrieve the data call it and await for the promise it returns:

// With async/await:
const db = await drive(SHEET_ID);
const db = await drive(options);
console.log(db);

// Use the callback syntax:
drive(SHEET_ID).then(db => console.log(db));
drive(options).then(db => console.log(db));

SHEET_ID: alias of options = { sheet: SHEET_ID }:

const db = await drive("1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k");
console.log(db);

options: a simple object containing some options:

const db = await drive({
  sheet: "1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k",
  tab: "1",
  cache: 3600
});
  • sheet (required): when editing a google spreadsheet, it's the part between /spreadsheets/ and /edit in the url. Please make sure to also publish the spreadsheet before copying it (File > Publish to the Web > Publish)
  • tab ("1"): the tab to use in the spreadsheet, which defaults to the first tab. It's the number as a string of the tab. See this demo as an example of how to load the second tab.
  • cache (3600): set the maximum time (in seconds) that the current cache is valid. After this, the data will be loaded again when the function is called. This is really useful when combined with development env constant. Set to 0 to refresh in each request.

It returns a plain Javascript array. With ES6+, operations on arrays are great, but feel free to use Lodash or similar if you want some more advanced queries.

If you are using server for Node.js with ES6+:

const drive = require("drive-db");
const sheet = "1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k"; // Or from .env

const server = require("server");
const { get } = server.router;
const { render } = server.reply;

const home = get("/", async ctx => {
  const records = await drive(sheet);
  return render("index", { records });
});

server(home);

Advanced

There are some more advanced things that you might consider. While I recommend you to read the code for this, here are a couple of examples.

Warm the cache

To warm the cache on project launch before the first request comes in, call the promise without awaiting or doing anything with it:

const drive = require("drive-db");
const sheet = "1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k";
// Warms the cache as soon as the Node.js project is launched
drive(sheet);

const server = require("server");
const { get } = server.router;
const { render } = server.reply;

const home = get("/", async ctx => {
  // Cache is already warm when this request happens
  const records = await drive(sheet);
  return render("index", { records });
});

server(home);

Refresh the cache

To force-refresh the cache at any point you can call drive() with a cache time of 0:

drive({ sheet, cache: 0 });

Load locally

This is not available anymore. Since drive-db returns a plain array, you can just load the data locally:

const data = require("./data.json");

Thanks to

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].