PouchDB for Deno, leveraging polyfill for IndexedDB based on SQLite.

Overview

PouchDB for Deno

PouchDB for Deno, leveraging polyfill for IndexedDB based on SQLite.

Usage

import PouchDB from 'https://deno.land/x/[email protected]+7.2.2/modules/pouchdb/mod.ts'

// Use the 'idb' afapter for IndexedDB and persistence to disk.
const db = new PouchDB('mydb', { adapter: 'idb' })
const doc = { hello: 'world' }
const result = await db.post(doc)

console.log(result)

const getDoc = await db.get(result.id)

console.log(getDoc)

const docs = await db.allDocs()

console.log(docs)

Features

All working plugins are included in the main export of PouchDB for Deno.

Out-of-the-box:

  • PouchDB-core imports into Deno without issue
  • HTTP/S instances appear to work using PouchDB-Server using the http plugin
  • PouchDB-Find plugin
  • PouchDB-MapReduce plugin
  • Replication

With work-arounds:

  • PouchDB-Adapter-IndexedDB
  • PouchDB-Adapter-Memory

Documentation

Nearly all documentation at PouchDB.com applies to this library. Known differences are called out below.

Adapters

Currently, the only adapters known to work in Deno are bootstrapped in this repository. However, new adapters written from scratch targeting Deno should work out-of-the-box when calling PouchDB.plugin. If new adapters written for Deno do not work, file issues and make sure to cross-link them in this repo and at PouchDB's repo.

IndexedDB

Since Deno does not ship with an official IndexedDB interface, it must be polyfilled for the related PouchDB adapter to work. IndexedDBShim makes this possible, on top of a WebSQL ponyfill written specifically for this codebase.

Should Deno ever implement this feature natively, the polyfill will be dropped to improve performance.

LevelDOWN

The only PouchDB adapter based on LevelDOWN known to work is the memory adapter. Local storage leveldown was tested and found to be incompatible. Other adapters threw errors from Skypack.dev CDN import; the message reported related to an out-of-date version of readable-stream NPM module.

Types

Augmentation was extremely difficult to perform by directly referencing PouchDB types from the DefinitelyTyped project. Instead, the relevant types were copied from DefinitelyTyped and merged by hand.

Why?

I did this because I love PouchDB, thought I could get PouchDB working, and I was impatient.

Thanos picks up Infinity Gauntlet; says "Fine, I'll do it myself."

Comments
  • feat: specify directory for `idb` sqlite files

    feat: specify directory for `idb` sqlite files

    Maybe I missed how to do this, but I would like to be able to specify the directory used to store the sqlite files created when using the idb adapter. Seems like current functionality only allows the cwd?

    On a hunch, I took a shot at just using prefix like what is described in Pouch docs with respect to LevelDB, but the result is the sqlite file name is prefixed:

    // results in a file in cwd named D__pouch_^12fpath^12fto^12ffilefoobar.sqlite
    new PouchDB.defaults({ adapter: 'idb', prefix: '/path/to/file'})("foobar")
    

    My use case is that I would like to be able to place the files into a directory, that the Deno task has permissions to write to ie. deno run --allow-write=/tmp/foo --allow-read=/tmp/foo foo.js

    Thanks!

    enhancement 
    opened by TillaTheHun0 18
  • small fix in adapter_idb, causing callback to be missing

    small fix in adapter_idb, causing callback to be missing

    I was getting a stack of errors (below) related to a missing callback, when running your couch port in the browser. Although I don't think browser usage was your intent I wanted to see if I could get it working.

    That said, I'm also importing this modified version of your port for a node-side instance of couch and it seems to be ok.

    From what I could see, declaring this as an arg in the function being run via call was causing the arguments to shift, so that the value of this was the options and the value of opts was the callback (for me anyways).

    This change seems to have unblocked things and I can now see the db created in the "browser storage inspector" (firefox).

    The error(s): Uncaught TypeError: fun is not a function tryCode pouchdb-adapter-idb.js:786 runCallback pouchdb-adapter-idb.js:801 completeSetup pouchdb-adapter-idb.js:1511 oncomplete pouchdb-adapter-idb.js:1543 onsuccess pouchdb-adapter-idb.js:1541 init pouchdb-adapter-idb.js:1476 IdbPouch pouchdb-adapter-idb.js:969 runAction pouchdb-adapter-idb.js:800 applyNext pouchdb-adapter-idb.js:796 enqueueTask pouchdb-adapter-idb.js:808 IdbPouch pouchdb-adapter-idb.js:968 idb mod.ts:41 PouchDB pouchdb-core.js:1401

    opened by elverskog 8
  • DISCUSSION: How to proceed with versioning

    DISCUSSION: How to proceed with versioning

    Since this project tries to simply re-export PouchDB, it would be good to co-version releases with the parent code. However, I foresee the need to implement bugfixed in the work-arounds and polyfills. A few ideas:

    • Break out WebSQL and IndexedDB polyfills into their own repo for independent versioning
    • Add a semver tag with own version, e.g. 7.2.2-DENOv1.0.0
    • Invert the tag relationship, like 1.0.0-POUCHDBv7.2.2
    • Version completely independent of PouchDB, and notify users of Pouch version changes via README

    Would happily take feedback and any other ideas out there.

    opened by aaronhuggins 3
  • Operations never resolve when using the `idb` adapter

    Operations never resolve when using the `idb` adapter

    Firstly, really awesome work here. I'm so excited to be able to use PouchDB in Deno!

    Something I came across, maybe I am missing something, it seems that operations hang when using the idb adapter. That is to say, the Promise never resolves.

    Reproduce:

    import PouchDB from "https://deno.land/x/[email protected]+7.2.2/modules/pouchdb/mod.ts";
    
    const db = new PouchDB('foobar', { adapter: 'idb' })
    
    console.log(db)
    
    // This Promise seems to never resolve
    console.log(await db.post({
      name: 'foo'
    }))
    
    console.log(await db.find({ selector: { name: 'foo' }}))
    

    I am able to use the memory adapter and things seem to work, so seems like something with idb polyfill?

    Thanks again.

    opened by TillaTheHun0 2
  • TASK: Upgrade to PouchDB 7.3.0

    TASK: Upgrade to PouchDB 7.3.0

    • [x] Include new feature to set directory path(s) for user and system IndexedDB sqlite databases #7
    • [x] Upgrade all dependencies to latest, but specifically PouchDB 7.3.0
    • [x] Expose the new BETA-quality indexeddb adapter; the Pouch team expect it to eventually replace idb
    • [x] Release to Denoland as 2.0.0-PouchDB+7.3.0
    task 
    opened by aaronhuggins 1
  • TASK: Migrate non-PouchDB modules to own repository

    TASK: Migrate non-PouchDB modules to own repository

    • [x] Move WebSQL to https://github.com/aaronhuggins/websql
    • [x] Move IndexedDB to https://github.com/aaronhuggins/indexeddb
    • [x] Publish modules to https://deno.land/x
    • [x] Update imports for IndexedDB and WebSQL in repository to new URLs
    opened by aaronhuggins 1
  • TASK: Add documentation

    TASK: Add documentation

    • [x] Explain usage of the main export
    • [x] Describe caveats for Deno
    • [x] Add links back to original PouchDB repository and packages, give proper credit
    • [x] Flesh out IndexedDB Shim pony/polyfill README
    • [x] Flesh out WebSQL ponyfill README
    • [x] Add license file (MIT)
    opened by aaronhuggins 1
  • TASK: Reduce hot-load time

    TASK: Reduce hot-load time

    Currently, on a hot-load, importing the main PouchDB module in this repository takes between 4.4 and 9.9 seconds. This module load time needs to be reduced.

    • [x] Experiment with plugin capture of idb adapter (would reduce network traversals and import evaluations by 18)
    • [x] Experiment with plugin capture of find plugin
    • [x] Research other bundled plugins
    bug 
    opened by aaronhuggins 0
Owner
Aaron Huggins
Open source developer and evangelist. If you're not using Deno at least as an experiment, you might be missing the next big thing in JavaScript.
Aaron Huggins
Querying Solana Blockchain, leveraging Magic Eden Apis!

Solana Bot Deployment Instructions- Create a bot on discord dev portal learn basics here Copy the Bot Token and go to OAuth field for URL generation F

Yog 5 Sep 8, 2022
A Deno ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud

A Deno ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud.

ʀᴀʏ 5 Dec 15, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
This is a simple boilerplate for a Deno website, deployed with Deno Deploy.

Simple Deno Website Boilerplate This is a simple website boilerplate built using Deno and deployed using Deno Deploy. Demo at simple-deno-website-boil

Bruno Bernardino 15 Dec 3, 2022
TypeSafe MongoDB Atlas Data API SDK for Deno & Deno Deploy

Atlas SDK atlas_sdk is a TypeSafe MongoDB Atlas Data API SDK for Deno & Deno Deploy Links Docs Import Replace LATEST_VERSION with current latest versi

Erfan Safari 20 Dec 26, 2022
Deno bindings for yoga, using Deno FFI.

deno_yoga Deno bindings for yoga, using Deno FFI. Usage flags: --allow-ffi: Requires ffi access to "yogacore.dll", "libyogacore.so", "libyogacore.dyli

迷渡 6 Feb 11, 2022
🛣️ A tiny and fast http request router designed for use with deno and deno deploy

Rutt Rutt is a tiny http router designed for use with deno and deno deploy. It is written in about 200 lines of code and is pretty fast, using an exte

Denosaurs 26 Dec 10, 2022
A small, but powerful HTTP library for Deno & Deno Deploy, built for convenience and simplicity

Wren Wren is a small, but powerful HTTP library for Deno & Deno Deploy, built for convenience and simplicity. convenient aliases for HTTP responses au

Jakub Neander 69 Dec 12, 2022
deno-ja (Deno Japanese community) showcase

Showcase Deno本家よりも気軽に作ったものを公開できるようなShowcaseです。 スクリーンショットの撮影方法 短めのidを決めていただいて、下記のようにスクリプトを実行してください。 deno task screenshot [url] [id] ※エラーが出る場合は、下記を実行してみ

deno-ja 17 Oct 28, 2022
A command-line tool to manage Deno scripts installed via deno install

??️ nublar nublar is a command-line tool to manage your scripts installed via deno install. ??️ Installation deno install --allow-read --allow-write -

Shun Ueda 16 Dec 26, 2022
Demo showcasing information leaks resulting from an IndexedDB same-origin policy violation in WebKit.

Safari 15 IndexedDB Leaks Description This demo showcases information leaks resulting from an IndexedDB same-origin policy violation in WebKit (a brow

FingerprintJS 101 Nov 5, 2022
IndexedDB with usability and remote syncing

IndexedDB with usability and remote syncing This is a fork of the awesome idb library, which adds the ability to sync an IndexedDB database with a rem

Damien Arrachequesne 8 Dec 14, 2022
fetch and process data in web worker, store in indexedDB.

Query+ install yarn add query-plus or pnpm add query-plus or npm install query-plus import import { useFetch, usePreFetch } from "query-plus" use

Rod Lewis 5 Aug 29, 2022
❇️ Doxor.js : more comfortable interacting with IndexedDB

doxor.js Offline database in Front-End library for interacting with IndexedDB Install Doxor.js using npm npm i doxor.js Creating a database import Do

Mojtaba Afraz 20 Oct 3, 2022
Persistent key/value data storage for your Browser and/or PWA, promisified, including file support and service worker support, all with IndexedDB. Perfectly suitable for your next (PWA) app.

BrowstorJS ?? ?? ?? Persistent key/value data storage for your Browser and/or PWA, promisified, including file support and service worker support, all

Nullix 8 Aug 5, 2022
Use plain functions as modifiers. Polyfill for RFC: 757 | Default Modifier Manager

Use plain functions as modifiers. Polyfill for RFC: 757 | Default Modifier Manager

null 7 Jan 14, 2022
Polyfill to remove click delays on browsers with touch UIs

FastClick FastClick is a simple, easy-to-use library for eliminating the 300ms delay between a physical tap and the firing of a click event on mobile

FT Labs 18.8k Jan 2, 2023