npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pouchdb-activerecord

v1.2.10

Published

PouchDb implementation of @hke/activerecord

Downloads

65

Readme

pouchdb-activerecord

npm version Build Status Maintainability Test Coverage

Example

import * as PouchDBMemory from 'pouchdb-adapter-memory';
import {
  PouchDbActiveRecord as ActiveRecord,
  PouchDbActiveQuery as ActiveQuery
} from './../src';
import { ModelAttribute } from '@hke/activerecord';

class Foo extends ActiveRecord {

  _id: string;
  foo?: string;
  goo?: number;

  static _identifier = '_id';
  static _tableName = 'Foo';
  static dbConfig = { adapter: 'memory', plugins: [PouchDBMemory] };

  public static _attributes: ModelAttribute[] = [
    new ModelAttribute('foo'),
    new ModelAttribute('goo'),
  ];
}

// instance creation
let model = new Foo({ foo: 'bar', goo: 1 });

// model gets values from constructor
console.log(model.foo); // 'bar'
console.log(model.goo); // 1

// has no id because it is a new (unsaved) record
console.log(model.isNewRecord); // true
console.log(model.id); // undefined

// .save() write record to db
await model.save();

// model got an id
console.log(model.isNewRecord); // false
console.log(model.id); // uuid

ActiveRecord

Methods

foo.save();
foo.find(); // returns ActiveQuery
Foo.findOne('uuid');
Foo.findOne({foo: 'baz'});
Foo.findAll();
Foo.findAll({goo: {$gt: 0}});

See options here

ActiveRecordRelation

The static methods create properties and methods on the given classes.

Methods

ActiveRecordRelation.hasOne(label: string, child: typeof ActiveRecord, property: string);
hasMany(label: string, child: typeof ActiveRecord, property: string);
manyToMany(label: string, child: typeof ActiveRecord, intermediate: typeof ActiveRecord, key: string, foreignKey: string)

ActiveRecordRelation.hasOne('a', Bar, 'a_id')

Defines a 1:1 relation. The method creates a and a_id on the parent class. model.a returns a Promise resolving in the Bar object. model.a_id contains the foreign pk id of the child object. The foreign object can be set with model.setA(object).

ActiveRecordRelation.hasMany('a', Bar, 'parent_id')

Defines a 1:n relation. The method creates a as property on the parent class. a is pluralized so it becomes as (if it would be as it stays as). model.as returns a Promise resolving in the related Bar objects. model.addA and model.addAs adds one or multiple foreign object and sets the parent_id property containing the parent id on the child object(s). model.getAs() returns a ActiveQuery with the foreign object ids preset in a $in condition.

ActiveRecordRelation.manyToMany('a', Bar, Foo_Bar, 'a_id', 'b_id')

Defines a n:m relation. The method creates a as property on the parent class. (label is bar, becomes bars). a is pluralized so it becomes as (if it would be as it stays as). model.as returns a Promise resolving in the related Bar objects. model.addA and model.addAs adds one or multiple foreign object and creates the relation entries in Foo_Bar with a_id containing the parent object id and b_id containing the child object id. model.getAs() returns a ActiveQuery with the foreign object ids preset in a $in condition.

ActiveQuery

You can do extended queries and filtering with ActiveQuery.

Methods

let query = new ActiveQuery(Foo); // or foo.find() (foo is instanceof ActiveRecord)
query
  .fields(param: string[])
  .sort(param: string[])
  .limit(start = 0, end = null)
  .where(condition: any = {})
  // call either one() or all()
  .one() // sets .limit(0,1) and returns Promise<type ActiveRecord>
  .all() // returns Promise<type ActiveRecord[]>

See where options here