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 🙏

© 2024 – Pkg Stats / Ryan Hefner

nativescript-couchbaselite

v1.0.11

Published

A NativeScript plugin that brings you all Couchbase Mobile features (attachments, ttl, map, reduce, group, encryption, conflicts, livequery, replication....). It targets iOS and Android.

Downloads

20

Readme

nativescript-couchbaselite

A nativescript plugin that brings you all couchbase features:

  • CRUD (with ttl...)
  • conflict management
  • CRUD attachment (file, image...)
  • View (map, mapreduce...)
  • Queries (full query features, live queries, all docs, group levels)
  • Replication (pull and push, filters, authentication, channels, listeners...)
  • Database encryption
  • Typescript mapping object (return objects with getters/setters...)

Author

How to use it

1- Import dependency

tns plugin add nativescript-couchbaselite

2- Samples

Import lib

import {
    QueryResult, LiveQuery, QueryListener, Revision,
    DatabaseManager, Document, Database, AttachmentFactory, Emitter, AttachmentImage
} from 'nativescript-couchbaselite';

class User implements Document {
    docId: string;
    docRev: string;
    docType: string = "USER";
    name: string;
    registerAt: number;
    secure: boolean = false;
    set registerAtDate(d: Date) {
        this.registerAt = d.getTime();
    }
    get registerAtDate() {
        return this.registerAt ? new Date(this.registerAt) : null;
    }
    @Type(() => Group) group: Group = new Group;
    getName() {
        return this.name;
    }
}

Create Database encrypted

let dbTest = DatabaseManager.getOrCreate({ name: "test", encryptionKey: "SECURE", create: true });

Map Typescript Objects

let mapping = new Map<string, any>();
mapping.set("USER", User);
dbTest.setMapping(mapping);

CRUD Document

let user = new User;
user.name = "user1";
user.group.name = "group1";
user.registerAtDate = now;
user.secure = true;       
dbTest.createDocument(user, "ID", { ttl: new Date() });
let fetched: User = <User>dbTest.getDocument(user.docId);
console.log(fetched.getName()); 
fetched.group.name = "group2";
dbTest.updateDocument(fetched.docId, fetched);               
let success = dbTest.deleteDocument(user.docId);

Crud Attachment

let source = fromResource("icon");
let attach = AttachmentFactory.fromSource(source, "yeah", AttachmentImage.PNG);
dbTest.setAttachment("ID", attach);
let attachments = dbTest.getAttachmentNames("ID");
let attach = dbTest.getAttachment("ID", "yeah");
removeAttachment("ID","yeah")

Create view

dbTest.createView({
    name: "users",
    revision: "1",
    map: (doc: User, emitter) => {
        if (doc.docType == "USER") {
            emitter.emit(doc.name.toLowerCase(), null);
        }
    }
})

Query View

let founded = dbTest.queryView("users", { mapOnly: true });
founded = dbTest.queryView("users", { mapOnly: true, startKey: "user4" });
founded = dbTest.queryView("users", { mapOnly: true, endKey: "user0" });
founded = dbTest.queryView("users", { mapOnly: true, startKeyDocID: "ID4" });
founded = dbTest.queryView("users", { mapOnly: true, endKeyDocID: "ID0" });
founded = dbTest.queryView("users", { mapOnly: true, descending: true });
founded = dbTest.queryView("users", { mapOnly: true, limit: 2 });
founded = dbTest.queryView("users", { mapOnly: true, skip: 3 });
founded = dbTest.queryView("users", { mapOnly: true, keys: ["user1", "user2"] });

Use compound keys

dbTest.createView({
    name: "users_compound",
    revision: "1",
    map: (doc: User, emitter) => {
        if (doc.docType == "USER") { 
            emitter.emit([doc.getName().toLowerCase(), doc.group.name.toLowerCase(), doc.registerAt, doc.registerAtDate, doc.secure], null); 
        }
    }
})

Use MapReduce

dbTest.createView({
    name: "users_bygroup",
    revision: "1",
    map: (doc: User, emitter) => {
        if (doc.docType == "USER") {
            emitter.emit([doc.group.name, doc.getName().toLowerCase()], doc.name);
        }
    },
    reduce: (keys: any[], values: any[], rereduce: boolean) => {
        return values.length;
    }
});

Group by levels

let founded = dbTest.queryView("users_bygroup", { mapOnly: false, groupLevel: 1 });
let groups = founded.getValues();

Query Result manager

let founded = dbTest.queryView("users_bygroup", { mapOnly: false, groupLevel: 1 });
let groups = founded.getValues();
let value = founded.firstValue();
let docs = <User[]>founded.getDocuments();
let doc = founded.firstDocument();
let docIds = founded.getDocumentIds();

Query all docs

let founded = dbTest.queryAllDocuments({ mapOnly: true });

Use LiveQuery

let listener = { 
    onRows(rows: QueryResult) { 
    }
};
let live = dbTest.liveQuery("users_live", { mapOnly: true }, l);
live.start();
live.waitForRows();
live.stop();

Push Replication

let url = "http://localhost:4984/test/";
let push = dbTest.createPushReplication(url);
push.setBasicAuthenticator("user", "password");
dbTest.createFilter({
    name: "filter",
    filter: (doc: Revision<Document>, params: Map<string, any>) => {
        return doc.id == "ID1";
    }
});
push.setFilter("filter");
let listener = {
    count: 0,
    onChange: (p) => {
        l.count = p.changesCount;
    }
};
push.addChangeListener(listener)
push.start();

Pull replication

let url = "http://localhost:4984/test/";
let pull = dbTest.createPullReplication(url);
pull.setBasicAuthenticator("user", "password");
let pullCallback = {
    countEvent: 0,
    onChange: (p) => {
        pullCallback.countEvent++;
    }
}
pull.channels(["channel4"]);
pull.setDocIds(["ID1"]);
pull.addChangeListener(pullCallback);
pull.start();

Conflict management

let conflicts = dbTest.getConflicts("ID");
let merged = mergeConflict(conflicts);
dbTest.resolveConflict("ID", merged);

Listen database events

dbTest.addChangeListener({
    onChange:(params:DatabaseListenerParam[])=>{

    }
});

Add any kind of attachment

class CustomAttachment implements Attachment{
    getName() => {
        return name;//String
    },
    getStream () => {
        return bs;//InputStream or NSData
    },
    getType () => {
        return "any/any";//Content Type
    }
}