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

react-native-db-models

v0.1.3

Published

Local DB Models for React Native Apps

Downloads

45

Readme

React Native DB Models React Native DB Models

License npm version

This wrapper is built on top of React Native Store and provides a better and improved Database layer for asynchronous DB transactions.

React Native DB Models fixes a lot of problems in react native store and also the DB class on top helps to provide more functionality and easy developing options.

NPM

New Feature added DB Emitter added on all write operations to the models. Which helps you maintain a global storage and re-rendering capabilities for your app.

Check the new documentation


Usage

The ideal way to use this library is to have a db.js in your applications somewhere. Which will be required.

DB.js

var RNDBModel = require('react-native-db-models')

var DB = {
    "app": new RNDBModel.create_db('app'),
    "users": new RNDBModel.create_db('users'),
}

module.exports = DB

and require it in your code -

var React = require('react-native');
var DB = require('./db.js');
// DB Emitter Initialized

var DBEvents = require('react-native-db-models').DBEvents
var {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    Image
    } = React;
    
// Only "all" event emitter is available

DBEvents.on("all", function(){
	console.log("Database changed");
})

var App = React.createClass({
	get_users: function(){
		DB.users.get_all(function(result){
			console.log(result);
		})
	},
	render: function(){
		return (
		<View>
			<Text onPress={this.get_users}> Hello </Text>
		</View>
		);
	}
});

All methods are async and therefore require a callback method.

You can check all the returned data from the callback. The returned data is more than expected so modify it as per your needs.


get

get(query_data, callback) query_data: The data to be matched. (eg. {name: "John Doe"})

Example

DB.users.get({first_name: "Rishabh"}, function(results){
	console.log(results);
})

get_id

get_id(id, callback) id: ID of the object to be fetched.

Example

DB.users.get_id(10, function(results){
	console.log(results);
})

get_all

get_all(callback) Gets the complete table for you.

Example

DB.users.get_all(function(result){
			console.log(result);
		})

remove

remove(query_data, callback) query_data: The data to be matched. (eg. {name: "John Doe"})

Example

DB.users.remove({first_name: "Rishabh"}, function(removed_data){
	console.log(removed_data);
})

remove_id

remove_id(id, callback) id: ID of the object to be deleted.

Example

DB.users.remove({first_name: "Rishabh"}, function(removed_data){
	console.log(removed_data);
})

add

add(data, callback) data: The data to be added. (eg. {name: "John Doe", age: 56})

Example

DB.users.add({first_name: "Rishabh", age: 25}, function(added_data){
	console.log(added_data); 
})

update

update(query_data, new_data, callback) query_data: The data to be matched. (eg. {name: "John Doe"}) new_data: The data to be updated. (eg. {age: 12})

Example

DB.users.update({first_name: "Rishabh"}, {age: 25}, function(updated_table){
	console.log(updated_table);
})

update_id

update_id(id, new_data, callback) id: The id of the data to be matched. new_data: The data to be updated. (eg. {name: "Ken"})

Example

DB.users.update_id(3, {name: "Ken", age: 12}, function(updated_table){
	console.log(updated_table);
})

erase_db

erase_db(callback) Erases the complete table.

Example

DB.users.erase_db(function(removed_data){
	console.log(removed_data);
})

More methods and features are gonna be added soon. Such as update, replace, constraints