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

@remobile/react-native-mongoose

v1.0.1

Published

A AsyncStorage based mongoose like storage for react-native

Downloads

3

Readme

React Native mongoose (remobile)

A AsyncStorage based mongoose like storage for react-native

Installation

npm install @remobile/react-native-mongoose --save

Usage

Example

'use strict';

var React = require('react');
var ReactNative = require('react-native');
var {
    StyleSheet,
    View,
    Image
} = ReactNative;
var {
    StyleSheet,
    View,
    AsyncStorage,
} = ReactNative;


var Button = require('@remobile/react-native-simple-button');
var Mongoose = require('react-native-mongoose');

const DB_NAME = "fang";
const CLT_NAME = "number";
module.exports = React.createClass({
    componentDidMount() {
        this.db = new Mongoose(DB_NAME);
        this.collection = this.db.collection(CLT_NAME, {max:30, unique:['a']});
    },
    doClear() {
        AsyncStorage.removeItem(DB_NAME);
    },
    doShowList() {
        (async function(){
            var list =  await AsyncStorage.getItem(DB_NAME);
            console.log('result:', JSON.parse(list));

        })();
    },
    doShowKeys() {
        (async function(){
            var list = await AsyncStorage.getAllKeys();
            console.log('result:', list);
        })();
    },
    async doInsert() {
        var info = {
            a : 4,
            b : 3,
        };
        var collection = this.collection;
        var list = await collection.insert(info).catch(error=>console.log(error));;
        console.log("list");
        console.log(list);
    },
    async doFind() {
        var collection = this.collection;
        var req = await collection.find();
        console.log(req);
    },
    async doFindOne() {
        var collection = this.collection;
        var req = await collection.findOne({b:3,a:1});
        console.log(req);
    },
    async doRemove() {
        var collection = this.collection;
        var req = await collection.remove();
        console.log(req);
        var req = await collection.find();
        console.log(req);
    },
    async doUpsert() {
        var collection = this.collection;
        var info = {
            a : 4,
            b : 6,
        };
        var list = await collection.upsert(info, {a:4}).catch(error=>console.log(error));;
        console.log("list");
        console.log(list);
    },
    render() {
        return (
            <View style={styles.container}>
                <Button onPress={this.doClear}>清除</Button>
                <Button onPress={this.doShowList}>列表</Button>
                <Button onPress={this.doShowKeys}>键值</Button>
                <Button onPress={this.doInsert}>Insert</Button>
                <Button onPress={this.doFind}>Find</Button>
                <Button onPress={this.doFindOne}>findOne</Button>
                <Button onPress={this.doRemove}>Remove</Button>
                <Button onPress={this.doUpsert}>Upsert</Button>
            </View>
        );
    }
});


var styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: 'transparent',
        justifyContent: 'space-around',
        paddingVertical: 150,
    },
});

method

  • creat dataBase

var db = new Mongoose(dbname);
* dbname: the name of database, in AsyncStorage it is a item key
  • clear memory

    db.clear();
* react-native-mongoose use memory chache database, when not use it, use it clear memory;
  • creat collection

var collection = this.db.collection(collectionName, capped);
* collectionName: the name of collection
* capped: {max: Number, unique:String|Array}
    * max: max rows in collection, if not set, have no limit
    * unique: set unique primary key, it can be a single String or a array for keys
  • insert

var doc = collection.insert(docs);
* docs: to be insert docs, if set capped.max, when reach capped.max, will be replace oldest one, if set capped.unique, e.g: capped.unique is 'a', then a is unique.
  • upsert

var doc = collection.upsert(docs, query, params);
* docs: need insert or update data
* query: look Query help
* params: {limit:Number, offset:Number, strict:bool};
    * limit: need upsert number
    * offset: need upsert start position
    * strict: set compare strict mode, look Query help
  • update

var doc = collection.upsert(docs, query, params);
* docs: need update data
* query: look Query help
* params: {limit:Number, offset:Number, strict:bool};
    * limit: need update number
    * offset: need update start position
    * strict: set compare strict mode, look Query help
  • remove

var doc = collection.remove(query, params);
* query: look Query help
* params: {limit:Number, offset:Number, strict:bool};
    * limit: need remove number
    * offset: need remove start position
    * strict: set compare strict mode, look Query help
  • find

var docs = collection.find(query, params);
* query: look Query help
* params: {limit:Number, offset:Number, strict:bool};
    * limit: need find number
    * offset: need find start position
    * strict: set compare strict mode, look Query help
  • findOne

var doc = collection.findOne(query);
* query: look Query help
* params: {limit:Number, offset:Number, strict:bool};
    * limit: 1
    * offset: need findOne start position
    * strict: set compare strict mode, look Query help

Query help

Query can be a object like {a:1, b:2}, or {a:{$eq:1}, b:{$eq:2}} also can be a function lick {a:function(a){return a>1}} operand like follows:

  • '$gt':
    return val1 > val2;
  • '$lt':
    return val1 < val2;
  • '$gte':
    return val1 >= val2;
  • '$lte':
    return val1 <= val2;
  • '$ne':
    return strict ? val1!==val2 : val1!=val2;
  • '$eq':
    return strict ? val1===val2 : val1==val2;
  • '$like':
    return new RegExp(val2).test(val1);