Code Monkey home page Code Monkey logo

sheet-down's Introduction

sheet-down

Build Status

A Google Spreadsheet implementation of leveldown.

This library uses abstract-leveldown to turn a worksheet within a Google Spreadsheet into a leveldown-compatible store for use with levelup. It was built to provide a convenient and familiar UI for two use cases:

  1. As a write-only store, to enable simple data entry without having to create or maintain a custom CRUD app with its own authentication/authorization.
  2. As a read-only view of an upstream data store, with built in sort and filter functionality.

Keep in mind that there are some differences between LevelDB and Google Spreadsheets. For example, unlike LevelDB, Google Spreadsheets does not guarantee batch write atomicity, and does not snapshot reads.

Currently only io.js has been tested.

Example

import fs from "fs"
import levelup from "levelup"
import {Token} from "google-oauth-jwt-stream"
import {CellDOWN} from "sheet-down"

let email = "[email protected]"
let key = fs.readFileSync("./key.pem")
let scopes = ["https://spreadsheets.google.com/feeds"]
let token = new Token(email, key, scopes)

let location = "<spreadsheet-id>/<worksheet-id>"
let table = levelup(location, new CellDOWN({token}))

table.batch()
  // put header row
  .put([1, 1], "name")
  .put([1, 2], "github handle")

  // put data rows
  .put([2, 1], "Jed Schmidt")
  .put([2, 2], "@jed")
  .put([3, 1], "Brian J. Brennan")
  .put([3, 2], "@brianloveswords")

  .write(err => {
    // read cells
    table.createReadStream().on("data", console.log)

    // { key: [ 1, 1 ], value: 'name' }
    // { key: [ 1, 2 ], value: 'github handle' }
    // { key: [ 2, 1 ], value: 'Jed Schmidt' }
    // { key: [ 2, 2 ], value: '@jed' }
    // { key: [ 3, 1 ], value: 'Brian J. Brennan' }
    // { key: [ 3, 2 ], value: '@brianloveswords' }
  })

screenshot

Installation

npm install sheet-down

Setup

Follow these steps to create and share a spreadsheet that this library can access, and get its spreadsheet and worksheet IDs.

API

import {CellDOWN, RowDOWN} from "sheet-down"

This backend provides two interfaces, for each cells and rows. Each of these constructors take an object whose token property is an instance of google-oauth-jwt-stream, and return an object whose db, keyEncoding, and valueEncoding properties match those accepted by levelup.

let cells = levelup("spreadsheetId/worksheetId", CellDOWN({token}))

This creates a backend that operates on a Google worksheet by cell. Each key is an 8-byte buffer of two UInt32BEs that specify the row number and column number, and each value is a utf-8 string. Unless otherwise specified, cell keys are transparently converted from integer arrays by the provided keyEncoding.

let rows = levelup("spreadsheetId/worksheetId", RowDOWN({token}))

This creates a backend that operates on a Google worksheet by row. Each key is a 4-byte UInt32BE that specifies the row number, and each value is a JSON-encoded string. Unless otherwise specified, cell keys are transparently converted from integers by the provided keyEncoding.

This backend is built on top of the cell interface by using the first row of the worksheet as a schema, grouping all cells in a given row into an array, and then using the schema keys to replace the column numbers with property names.

sheet-down's People

Contributors

jed avatar psychollama avatar nolanlawson avatar

Stargazers

 avatar Conch Roman avatar Vedanta-krit das (Alex Vedmedenko) avatar Doug A avatar Huan Li avatar Jan Z avatar  avatar Adrian Praja avatar Ryoji Miyazato avatar Andrejs Agejevs avatar Antoninko avatar liujian zhang avatar Orange Mug avatar lorezz avatar Guillaume Clochard avatar Max Bernstein avatar Oleg Akinin avatar  avatar Nikita Skazki avatar Artur Paikin avatar  avatar Gaëtan Ark avatar Vishnu Airy (Aero-vision) avatar  avatar Khang Hoang avatar Gabe Montalvo avatar Jason Miller avatar cybai (Haku) avatar Yosh avatar Jacky Alciné avatar Jamie Kyle avatar Mike Vegeto avatar Tim Kevin Oxley avatar Minh Nguyen avatar Foy Savas avatar citymont avatar Angus H. avatar  avatar jon ⚝ avatar Josh Duff avatar Brad Pillow avatar Simon Tegg avatar Mikey avatar Joao P Dubas avatar Chris Callahan avatar Ignacio avatar Bruno Vieira avatar jcrubino avatar Charlike Mike Reagent avatar Carlos Villuendas Zambrana avatar Sergey Todyshev avatar leroy li avatar Rahul Singh avatar Alex Mykyta avatar Sebastien Ballesteros avatar Nikolay Kolev avatar Krister Kari avatar Dave Gramlich avatar Joshua Suggs avatar Yaniv Kessler avatar atsumo avatar Rodrigo G. López avatar Phan An avatar Chee Aun avatar hashrock avatar Tri Nguyen avatar Shern Shiou Tan avatar Fabiano avatar maboiteaspam avatar Yuya Saito avatar Todd Price avatar Eirik L. Vullum avatar Michael DeRazon avatar Bence Dányi avatar Andrew Sutherland avatar John Resig avatar Seth Vincent avatar Cristian Douce avatar Jordan Burke avatar Bo Link avatar  avatar Marwan Hilmi avatar jiangplus avatar xeodou avatar Dan Levy avatar Matt Mueller avatar t m avatar Takashi Fujita avatar Po-Ying Chen avatar Bo-Yi Wu avatar Gary Chou avatar Derek Reynolds avatar Denis Denisov avatar Sri Dodda avatar  avatar Breno Polanski avatar Lucifero Von Nachtosphere avatar Stanley Zheng avatar  avatar Scott Elcomb avatar

Watchers

James Cloos avatar Krister Kari avatar  avatar

sheet-down's Issues

First argument must be an abstract-leveldown compliant store

I try to run the homepage example with those version

  "dependencies": {
    "google-oauth-jwt-stream": "^1.0.4",
    "levelup": "^3.1.1",
    "sheet-down": "^1.1.3"
  }

But i have this error

node index.js

/web/sheet-down/example/node_modules/levelup/lib/levelup.js:49
    throw error
    ^
InitializationError: First argument must be an abstract-leveldown compliant store
    at new LevelUP (/web/sheet-down/example/node_modules/levelup/lib/levelup.js:45:13)
    at LevelUP (/web/sheet-down/example/node_modules/levelup/lib/levelup.js:29:12)
    at Object.<anonymous> (/web/sheet-down/example/index.js:12:13)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)

Build failure: LevelDOWN undefined

In package.json, "abstract-stream-leveldown" was listed as any version *, and a breaking change hit through a rename. sheet-down.js tries to import LevelDOWN, but the name has since been changed to AbstractStreamLevelDOWN, leaving things undefined, causing an error to be thrown if the user tries to require the module.

require('sheet-down')
// TypeError: Super expression must either be null or a function, not undefined

^^ caused by import misnomer.

Error running example

sheet-down\dist\cell\LevelDOWN.js:103
              throw _iteratorError;
                    ^
ReferenceError: Symbol is not defined

The value cannot contains '&'

Currently, the value of cell or row cannot contains &, if so, the put command will be ignored, without errors.

My use case need to store some url into the google sheet.
Using encodeURIComponent to turn the & into %26 works as a workaround to store the content on the sheet, however, the hyperlink from the google sheet web UI will not match with the original url.

How can we fix this?

Update: The limitation seems to come from https://github.com/jed/google-worksheet-stream

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.