Giter Site home page Giter Site logo

zangodb's People

Contributors

erikolson186 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zangodb's Issues

Creating an instance with a collection string array doesnt work

I wanted to create an instance of zangodb and passed the database name and a string array with the collections, but in my code he wants then a version parameter.

I saw in your db.js file on line 55 that you only check if the second parameter is an object and not if its an string array, so you definitly need a version parameter, when you pass only a string array with the collections.

Update: But i noticed that i have to pass a version parameter anyway, because i use Typescript. But dont know if it is intended with the missing type check in your code.

query on nested object path

Nice library... keep up the good work

I have a question, while the below is supported

col.find({ x: 4, g: { $lt: 10 } }, { k: 0 })

Will querying on nested objects path be supported too like in mongo

col.find({ 'person.age' : { $lt: 10 } })

Error code

Now the error comes with message only like this:

"Error" "Key already exists in the object store."

Is it possible to use message code as error name? Much easier to use switch or other expression to identify.

update whole object

I notice that there is no save method, does that mean the best way to do save with existing object is to delete first then insert?

Now the API is not easy to implement upsert. I need findOne first then if the id is found, in order to update I have to call update which will filter the collection again, which is kind of slow in large collection.

Query array property

Hi,

Is it possible to query an array property of a document. Given the following structure of my documents, I want to query for documents where Id15 contains 37330006.

{
  "Id15":["37330006", "37330007", "37330008"],
  "Name":"John Smith",
  "Address":"The street 152",
   "Postal":"90210",
   "City":"BH",
   "Cvr":"1123123234",
   "_id":25953
}

BR
Thomas

Cursor and Collection types are not generic

Under the current type definitions, collections and cursors return documents that are always typed as Object. This means that when using TypeScript, documents must always be type-asserted to a concrete type before being used:

const db = new zango.Db('mydb');
const people = db.collection('people');

const person = people.find({ name: 'John' });
person.name = 'Mike'; // ERROR: Property 'ok' does not exist on type 'Object'.

interface Person {
  name: string;
}

const person2 = people.find({ name: 'John' }) as Person;
person.name = 'Mike'; // OK

This happens because current type definitions are hard-typed to Object and do not allow generics:

zangodb/src/zangodb.d.ts

Lines 21 to 31 in 868babf

export class Collection {
name: string;
aggregate(pipeline: Object[]): Cursor;
find(expr: Object, projection_spec?: Object): Cursor;
findOne(expr: Object, projection_spec?: Object,
cb?: ResultCallback<Object>): Promise<Object>;
insert(docs: Object|Object[], cb?: Callback): Promise<void>;
remove(expr: Object, cb?: Callback): Promise<void>;
update(expr: Object, spec: Object, cb?: Callback): Promise<void>;
}

We could get inspired by mongodb's type definitions at DefinitelyTyped, and generalize Cursor and Collection, allowing the library consumer to set the document's interface for a given collection, falling back to Record<string, any> if the type parameter is not supplied:

mongodb's Collection type signature - allows a type parameter

mongodb's Collection#findOne type signature - leverages collection type parameter

Using a similar sytem, we could accomplish the following with TypeScript:

interface Person {
  name: string;
}

const db = new zango.Db('mydb');
const people = db.collection<Person>('people');

const person = people.find({ name: 'John' }); // typeof person == Person
person.name = 'Mike'; // OK

I can go ahead and write a quick PR to fix this if you'd like.

hint error

collection.find().sort({ x: 1 }).hint('x').toArray() will get this error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'args')
    at removeClause (create_next_fn.js:39:1)
    at create_next_fn.js:357:1
    at createGetIDBReqFn (create_next_fn.js:358:1)
    at createGetIDBCurFn (create_next_fn.js:378:1)
    at createNextFn (create_next_fn.js:521:1)
    at push../node_modules/zangodb/build/src/create_next_fn.js.module.exports (create_next_fn.js:572:1)
    at Cursor._init (cursor.js:321:1)
    at Cursor._forEach (cursor.js:62:1)
    at Cursor._toArray (cursor.js:115:1)
    at Cursor.toArray (cursor.js:142:1)

indexes doesn't change when modify database design and version number

Hi there
I'm using zangodb in chrome extension development.
The problem is that when I use the config object and version number to upgrade the database version to the new version, the indexes has not changed, but the version number has changed.

These two configurations are like this:

// version 1
let DBStruct  = {
	user: 	{"userid":true},
};
// version 2
let DBStruct  = {
	user: 	{"uid":true,"userid":false},
};

The uid index not created, and userid is still there.

find where array field contains at least one element with the specified value

let db = new zango.Db('searcher', { people: ['uids'] });
let people = db.collection('people');

let docs = [
    { name: 'Frank', uids: ['1', '2', '3'] }
];

people.insert(docs).then(() => {
   console.log('save success');
    return people.find({
        uids: '2'
    }).forEach(doc => console.log('doc:', doc));
}).catch(error => console.error(error));
> save success

The search for an element within an array is not supported?

Add count support

How to get count directly?

people.find({ name: { $regex: /Todd/ } }).toArray().then(res => console.log(res.length)).catch(err =>console.log(err))

may be add count support?
people.count({ name: { $regex: /Todd/ } }).then(res => console.log(res)).catch(err =>console.log(err))

ZangoDB does not create IndexedDB collection

I have the following code:

db.js

import zango from 'zangodb';

const db = new zango.Db('app', {
  translations: ['id'],
  services: ['id', 'key'],
  console: true
});

export default db;

logger.js

import db from 'environment/db';

class Logger {

  static log(message, type) {
    db.collection('console').insert({
      timestamp: 'test',
      message,
      type
    }, (error) => {
      if (error) {
        throw error;
      }
      console.log('success');
    });
  }

}

export default Logger;

test.js

import Logger from 'environment/logger';

Logger.log('test log', 'info');

I keep getting the following error:

NotFoundError (DOM IDBDatabase Exception 8): Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.

My other two collections (services and translations) work properly but for some reason the 3rd one does not run. What am I missing here?

$nin operator seems like fail with empty array

const exclude = loadedItems.map(item => item._id);

The following query doesn't work (gives back zero elements) when the exlude is an empty array. Tested many different ways.

const query = searchValue ? {
parentId: { $eq: selectedFolderId },
_id: { $nin: exclude },
name: { $regex: searchValue, $options: "i" },
} : {
parentId: { $eq: selectedFolderId },
_id: { $nin: exclude },
}

Custom query filter

First of all, thank you for such an amazing library. It has been of a tremendous help for us at distill.io when we needed to transition from SQLite to tIndexedDB to build our Firefox web extension.

There is a type of find query that we are not able to use ZangoDB. In this query, one needs to compare one field with another. For example price > threshold. Is there a way to perform such queries?

In general, can one use a function that can perform arbitrary operation in JavaScript and return a boolean value to filter records? Such an API can enable a wide range of queries that may not be possible at this moment.

Thoughts?

$in operator not working properly

The $in operator always fetch one record.

I have very simple database structure as shown below

zangodb

I am trying to fetch all those records which have name field value 'Bill' or 'Don' I am using $in operator but it always return only one row. Below is the code that I am using

let db = new zango.Db('customer_db', { customers: ['snn'] });
let people = db.collection('customers');

people.find({
	name: { $in: ["Don","Bil"]}
}).forEach(doc => console.log('doc:', doc));

and the output of above code is

output

@erikolson186 can you please help me know to resolve above issue?

Request: Example of JOIN

I'm looking for an alternative to NeDB which seems abandoned a little for a node-webkit app.

Could I see an example of a join operation? I'm not quite sure how I should do it with ZangoDB.

I'm familiar with EJDB join requests but I prefer a library that would avoid me to compile stuff.

db.find('orders', {$do: {member: {$join:'members'}}});

Thanks!

How can I find out that the search is completed?

How can I find out that the search is completed to start another operation after the search?

let db = new zango.Db('searcher', { people: ['uids'] });
let people = db.collection('people');

let docs = [
    { name: "1", gender: "m", uids: ['1', '2', '3'] },
    { name: "2", gender: "m", uids: ['1', '2', '3'] },
    { name: "3", gender: "m", uids: ['1', '2', '3'] },
    { name: "4", gender: "m", uids: ['1', '2', '3'] }
];

people.insert(docs).then(() => {
		console.log('save success');
}).catch(error => console.error(error));
people.find({
        name: {$in: ["1"]},
        gender: "m"
}).toArray((error, doc) => console.log('doc:', doc));
console.log('start another operation');
(index):70 start another operation
(index):64 save success
(index):69 doc: (3) [{…}, {…}, {…}]

updated value doesn't take effect immediately

I write the upsert method like this:

    public upsert(doc: Object, collectionName: string) {
        if (!doc) return Promise.reject('invalid doc');
        doc['updatedAt'] = Date.now();
        let id = doc['_id'];
        if (id) {
            return this.get(id, collectionName)
                .toArray((err: Error, docs: Object[]) => {
                    if (!err && docs && docs.length === 1) {
                        // found one, update
                        return this.collection(collectionName).update({ _id: id }, doc);
                    } else {
                        // found no record, insert
                        return this.insert(doc, collectionName);
                    }
                });
        } else {
            // missing _id, insert directly
            return this.insert(doc, collectionName);
        }
    }

And I call it like this:

    public try() {
        this.db.upsert({ _id: '12345', name: '123' }, DbService.COL_MAIN)
            .then(insertResult => {
                this.db.find({}, DbService.COL_MAIN)
                    .forEach(doc => {
                        console.log('result:', doc);
                    });
            })
            .catch((err: Error) => console.error(err, err.name, err.message));
    }

The value of name 123 is not updated in the inner find and forEach. That's to say when I call find the updates are not guaranteed?

Operator similar to LIKE in SQL

Is it possible to have something similar to LIKE operator in SQL? Mongo supports regex.

Either way, would love to know your thoughts on this. This is useful when writing queries that search for keywords in documents.

not be possible to append new collections

After creating multiple collections for the first time, it will not be possible to append new collections, I would like to be able to append collections at a later stage, but there is no corresponding api at the moment

aggregate ignores order of sort and skip

Mongodb aggregate follows the order specified in pipeline. But zangodb does not appear to. I think that I must be missing something. Following is an adapted example from issue #9 :

var db = new zango.Db(Math.random(), { col: ['x', 'g'] });
var col = db.collection('col');
var docs = [{ x: 2, g: 3 }, { x: 2, g: 8 }, { x: 2, g: 8, z: 10 }, { x: 3, z: 3, g: 4 }, { x: 4, k: 8, g: 1 }, { x: 6, g: 9 }, { x: 10, k: 4 }, { x: undefined }, { x: null }, { x: [{ k: 2 }, { k: 8 }] }];
col.insert(docs);

col.aggregate([{$skip : 2}, {$sort: {g: -1} }, ]).toArray().then(docs => {
  console.log(docs.map(doc => doc.g))
});

col.aggregate([{$sort: {g: -1} }, {$skip : 2}]).toArray().then(docs => {
  console.log(docs.map(doc => doc.g))
});

Output in both cases is:

(8) [undefined, undefined, undefined, undefined, 9, 8, 4, 1]

What is the correct way to query a collection, sort it and then use skip and limit? I am trying to do this to paginate ordered data.

Many thanks for this wonderful library. With its help, using IndexedDB has been a joy!

TypeError: #<Object> is not a function

Why does the following code produce the error in the title?

(async () => {
  let res = await window.db.collection('change_queue')
              .find({})
              .sort({timestamp: -1})
  res = await res.toArray()
  console.log("RES", res)
})()

typeof timestamp is Date btw. Seems to be working without the sort() part

is $pull supported?

Hi Again,

Just curious if $pull is supported. I have requirement to pull/remove items from an nested array. Is there a way to do so?

Relation between size of docs and insert speed

Hello,

Thank you for a great framework.

I have a question. Have you done any benchmarking on inserts. I'm trying to figure out the optimal size for the docs array, when inserting into a collection using:

collection.insert(docs).then(function () { ... });

Or rather i'm trying to figure out if I need to split the array into chunks.

BR
Thomas

Index all fields of array of objects

Hi!
Giving this data:

{
  "_id": "12451234",
  "tracks": [
    {"creation": "2017-11-12", "text": "asfdasdfas"},
    {"creation": "2017-11-11", "text": "asdfadsfasd"},
  ]
}

is it possible to index tracks.creation?
How?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.