0.0.15 • Published 7 months ago

@strangebytes/pouchdb-orm v0.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Pouchdb ORM

This is a simple ORM/ODM for storing and fetching data in PouchDB using Zod for schema definition and validation.

Example

import PouchDB from 'pouchdb'
import pouchFind from 'pouchdb-find'
import {z} from 'zod'
import {Collection} from '@strangebytes/pouchdb-orm'

const pouchDB = new PouchDB('example')
PouchDB.plugin(pouchFind)

// All schema's require _id and _rev
const baseSchema = z.object({
    _id: z.string(),
    _rev: z.string().optional()
})
const exampleSchema = baseSchema.extend({
    foo: z.string(),
})
const exampleCollection = new Collection(pouchDB, 'example', exampleSchema)

// Create a document
const {ok, id, rev} = await exampleCollection.put({
    _id: 'hello',
    foo: 'bar',
})

// Update a document by specifying id and revision
await exampleCollection.put({
    _id: id,
    _rev: rev,
    foo: 'baz',
})

// Find documents in a collection
// See documentation in PouchDB/CouchDB for querying
// https://pouchdb.com/api.html#query_index
const examples = await exampleCollection.find()

// Find a document
const example = await exampleCollection.findById('hello')

// Update an existing document without needing to manually pass a revision
await exampleCollection.update({
    _id: 'hello',
    foo: 'something else',
})

// Remove a document by ID
await exampleCollection.removeById('hello')

Under the hood

This project aims to be as lightweight of a wrapper around PouchDB as is possible. Collections add a type of "$collection" in order to enable querying by collection, and that's about it.

Roadmap

  • Creating documents with validation
  • Fetching documents with validation
  • Support Mango queries
  • Migration System
  • Fancy data viewer
  • Graceful error handling
  • Live Queries
0.0.15

7 months ago

0.0.14

10 months ago

0.0.13

10 months ago

0.0.12

10 months ago

0.0.11

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago