Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @neoskop/adamant with all npm packages installed. Try it out:

require("fast-deep-equal/package.json"); // fast-deep-equal is a peer dependency. require("@angular/core/package.json"); // @angular/core is a peer dependency. require("injection-js/package.json"); // injection-js is a peer dependency. var adamant = require("@neoskop/adamant")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@neoskop/adamant v0.2.0

PouchDB ORM

@neoskop/adamant

PouchDB ORM written in pure Typescript
adamant: too hard to cut, break, or pierce.

Master
Travis master Test coverage master Known Vulnerabilities master

Develop
Travis develop Test coverage develop Known Vulnerabilities develop

Features

  • Define your entities and design docs with annotations
  • design docs
    • views
    • filters
    • validate_doc_update (with PouchDB-Plugin or CouchDB)
  • Relations
    • belongsTo
    • hasMany/hasManyMap
    • inline

Installation

$ yarn add @neoskop/adamant

$ npm i @neoskop/adamant

Usage

Write you entities/interfaces at once
An entity requires an Entity and an Id annotation.

@Entity('person')
class PersonEntity {
    @Id()
    id!: string;

    @Property()
    name?: string;
}

Create/update/read from database

declare const connection: AdamantConnectionManager;

const repo = connection.getRepository(PersonEntity);

const person = repo.build({ id: '1', name: 'Jon Doe' });

await repo.create(person); // persist in database

person.name = 'Jane Doe';

await repo.update(person); // update database entry
await repo.upsert(person); // inserts/updates if needed

const personCopy = await repo.read('1'); // personCopy equals person

await repo.delete(personCopy); // marks database entry as deleted (_deleted = true)

Create and resolve relations

@Entity('class')
class ClassEntity {
    @Id()
    id!: string;

    @HasMany(Person)
    persons?: Person[];
}

const classRepo = connection.getRepository(ClassEntity);
const personRepo = connection.getRepository(PersonEntity);

const janeDoe = personRepo.build({ id: '1', name: 'Jane Doe' });
const jonDoe = personRepo.build({ id: '2', name: 'Jon Doe' });

await personRepo.bulk.create([janeDoe, jonDoe]); // persist multiple entities at once

const cls = classRepo.build({ id: '2a', persons: [janeDoe, jonDoe] });

await classRepo.create(cls); // relations will be replace with their id's

Angular Module

@NgModule({
    imports: [
        CommonModule,
        AdamantModule.forRoot({
            factory: …,
            entities: […],
            designDocs: […]
        })
    ]
})
export class AppModule {}

Development

Install dependencies

$ yarn

Run tests

$ yarn test
$ yarn run coverage

Build

$ yarn build

License

MIT License

Copyright (c) 2018 Neoskop GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Sponsor

Neoskop GmbH

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free