0.0.15 • Published 5 months ago

@strangebytes/pouchdb-orm v0.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
5 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

5 months ago

0.0.14

8 months ago

0.0.13

8 months ago

0.0.12

8 months ago

0.0.11

8 months ago

0.0.10

8 months ago

0.0.9

8 months ago

0.0.8

8 months ago

0.0.6

8 months ago

0.0.5

8 months ago

0.0.4

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago