🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️

Overview

WatermelonDB

A reactive database framework

Build powerful React and React Native apps that scale from hundreds to tens of thousands of records and remain fast ⚡️

MIT License npm

WatermelonDB
⚡️ Launch your app instantly no matter how much data you have
📈 Highly scalable from hundreds to tens of thousands of records
😎 Lazy loaded. Only load data when you need it
🔄 Offline-first. Sync with your own backend
📱 Multiplatform. iOS, Android, and the web
⚛️ Works with React. Easily plug data into components
Fast. And getting faster with every release!
Proven. Powers Nozbe Teams since 2017 (and many others)
Reactive. (Optional) RxJS API
🔗 Relational. Built on rock-solid SQLite foundation
⚠️ Static typing with Flow or TypeScript

Why Watermelon?

WatermelonDB is a new way of dealing with user data in React Native and React web apps.

It's optimized for building complex applications in React Native, and the number one goal is real-world performance. In simple words, your app must launch fast.

For simple apps, using Redux or MobX with a persistence adapter is the easiest way to go. But when you start scaling to thousands or tens of thousands of database records, your app will now be slow to launch (especially on slower Android devices). Loading a full database into JavaScript is expensive!

Watermelon fixes it by being lazy. Nothing is loaded until it's requested. And since all querying is performed directly on the rock-solid SQLite database on a separate native thread, most queries resolve in an instant.

But unlike using SQLite directly, Watermelon is fully observable. So whenever you change a record, all UI that depends on it will automatically re-render. For example, completing a task in a to-do app will re-render the task component, the list (to reorder), and all relevant task counters. Learn more.

React Native EU: Next-generation React Databases WatermelonDB Demo

📺 Next-generation React databases
(a talk about WatermelonDB)

Check out web Demo

Usage

Quick (over-simplified) example: an app with posts and comments.

First, you define Models:

class Post extends Model {
  @field('name') name
  @field('body') body
  @children('comments') comments
}

class Comment extends Model {
  @field('body') body
  @field('author') author
}

Then, you connect components to the data:

const Comment = ({ comment }) => (
  <View style={styles.commentBox}>
    <Text>{comment.body} — by {comment.author}</Text>
  </View>
)

// This is how you make your app reactive! ✨
const enhance = withObservables(['comment'], ({ comment }) => ({
  comment,
}))
const EnhancedComment = enhance(Comment)

And now you can render the whole Post:

const Post = ({ post, comments }) => (
  <View>
    <Text>{post.name}</Text>
    <Text>Comments:</Text>
    {comments.map(comment =>
      <Comment key={comment.id} comment={comment} />
    )}
  </View>
)

const enhance = withObservables(['post'], ({ post }) => ({
  post,
  comments: post.comments
}))

The result is fully reactive! Whenever a post or comment is added, changed, or removed, the right components will automatically re-render on screen. Doesn't matter if a change occurred in a totally different part of the app, it all just works out of the box!

➡️ Learn more: see full documentation

Who uses WatermelonDB

Nozbe Teams
CAPMO
Steady
Aerobotics
Smash Appz
Rocket Chat
HaloGo
SportsRecruits

Does your company or app use 🍉 ? Open a pull request and add your logo/icon with link here!

Contributing

We need you

WatermelonDB is an open-source project and it needs your help to thrive!

If there's a missing feature, a bug, or other improvement you'd like, we encourage you to contribute! Feel free to open an issue to get some guidance and see Contributing guide for details about project setup, testing, etc.

If you're just getting started, see good first issues that are easy to contribute to. If you make a non-trivial contribution, email me, and I'll send you a nice 🍉 sticker!

If you make or are considering making an app using WatermelonDB, please let us know!

Author and license

WatermelonDB was created by @Nozbe. Main author and maintainer is Radek Pietruszewski.

Contributors: @mobily, @kokusGr, @rozPierog, @rkrajewski, @domeknn, @Tereszkiewicz and more.

WatermelonDB is available under the MIT license. See the LICENSE file for more info.

Comments
  • Override entity IDs

    Override entity IDs

    Hey,

    we are currently evaluating this for our app. Since we try to implement our own sync engine on top, I'd be curious if it's possible to specify entity IDs whenever you create one.

    Right now, if I try to set an ID in the builder function, I get the following error:

    Diagnostic error: Attempt to set new value on a property Model.prototype.id marked as @readonly

    Great work by the way, this looks very promising!

    opened by sebastian-schlecht 38
  • Initial Sync Download

    Initial Sync Download

    I see in the docs the Sync API function pullChanges uses a fetch request to get the change in records

    My question is how does this fetch request handle large amounts of data, for example if an existing users, gets a new device and has to download 500,000+ records linked to their profile? Is there a way of initialising the watermelon db from the remote DB and guarantee all the data is there?

    opened by PatrickLambert1101 35
  • Adds rawQuery functionality

    Adds rawQuery functionality

    Adds rawQuery functionaility, but needs Flow coverage.

    Usage:

    const tableNameCollection = database.collections.get('table_name')
    tableNameCollection.unsafeFetchRecordsWithSQL('select * from ...')
    
    database.adapter.unsafeSqlQuery('select * from ...', 'table_name')
    

    Issue: #103

    opened by zobeirhamid 33
  • Database failed to load error

    Database failed to load error

    After some time spent to set up this package in react native, got this error:

    [DB] Uh-oh. Database failed to load, we're in big trouble, [TypeError: undefined is not an object (evaluating 'Native.setUp')]

    I am using expo for development.

    opened by theixbass 32
  • Request for TypeScript support

    Request for TypeScript support

    This project looks fantastic and it would be great to get TypeScript support as well. TypeScript has quite a big community but with this being quite a new project there doesn't appear to be a community definition yet. I'd be happy to have a crack at helping with this, but I have not written an index.d.ts definition before. Microsoft have a guide over at https://www.typescriptlang.org/docs/handbook/declaration-files/by-example.html.

    good first issue 
    opened by c-kirkeby 29
  • Batch Seeding Performance

    Batch Seeding Performance

    I'm currently running into issues while trying to use batch to seed my database. I have collections of around 50K records, which caused me to run into memory issues I assume are mentioned in #308.

    Since I'm using batch and not sync I added my own limit of around 1000 to get around the memory issue. This however has lead to very slow initial seeding performance (taking minutes to populate fully).

    #403 mentions using the new flag to achieve the 5K batch size, but I'm not sure if they've run into the slow seeding performance or not.

    Anybody had to deal with this case, or the general case of populating watermelon with many records?

    wontfix 
    opened by bzvikler 28
  • NodeJS client

    NodeJS client

    Fix #721

    note: I wanted to have the js files in the ./native folder, but as it is out of the ./src folder, I decided to change.

    pending tests, suggestions welcome cc @radex

    opened by sidferreira 24
  • [Bug][iOS] 'jsi/jsi.h' file not found

    [Bug][iOS] 'jsi/jsi.h' file not found

    Hi!

    After update from 0.16.0 to 0.16.1 I get this error:

    In file included from /node_modules/@nozbe/watermelondb/native/ios/WatermelonDB/JSLockPerfHack.mm:1:
    
    /node_modules/@nozbe/watermelondb/native/ios/WatermelonDB/JSLockPerfHack.h:3:10: fatal error: 'jsi/jsi.h' file not found
    #include <jsi/jsi.h>
             ^~~~~~~~~~~
    1 error generated.
    
    Screenshot 2020-05-19 at 13 03 05
    opened by kesha-antonov 22
  • An in-range update of eslint-plugin-jest is breaking the build 🚨

    An in-range update of eslint-plugin-jest is breaking the build 🚨

    The devDependency eslint-plugin-jest was updated from 22.9.0 to 22.10.0.

    🚨 View failing branch.

    This version is covered by your current version range and after updating it in your project the build failed.

    eslint-plugin-jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

    Status Details

    Release Notes for v22.10.0

    22.10.0 (2019-07-17)

    Features

    Commits

    The new version differs by 7 commits.

    • 28bd1dc feat(rules): adds no-if rule (#293)
    • 7ebdc0e chore: enforce import destructure order
    • 31c7cef chore: convert to import/export (#302)
    • 9f858cb chore: delete tests instead of ignoring them with babel
    • c595ba0 chore: do not include tests in published tarball
    • 4b4eb78 chore: fix lint error in md file
    • d3ea720 chore(docs): fix typo (#304)

    See the full diff

    FAQ and help

    There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper Bot :palm_tree:

    greenkeeper 
    opened by greenkeeper[bot] 20
  • Sync error handling

    Sync error handling

    Are there any good examples of error handling for sync in both the frontend and backend that I can reference? I'm having trouble with the pullChanges & pushChanges changing records to synced even though some records failed to be pushed or pulled.

    EDIT: I added try catch to throw 503 error if any error occurs and it works but something about it feels off

    opened by KrisLau 19
  • TypeError: from.from is not a function. (In 'from.from(observables[0])', 'from.from' is undefined)

    TypeError: from.from is not a function. (In 'from.from(observables[0])', 'from.from' is undefined)

    Here is my component

    const PlaylistItem = ({playlist}) => {
      console.log(playlist);
        return (
        <List.Item
          title={playlist.title}
          description="by you"
          left={props => <List.Icon {...props} icon="audiotrack" />}
        />
      );
    };
    
    const enhance = withObservables(['playlist'], ({playlist}) => ({
      playlist
    }));
    
    export default enhance(PlaylistItem);
    

    Here is how I call the component

    <FlatList
              data={this.state.playlists}
              renderItem={(item) => <PlaylistItem playlist={item} />}
            />
    

    This is my query

    async componentDidMount(){
        const playlists = database.collections.get('playlists');
        const allPlaylists = await playlists.query().fetch();
        console.log("playlist ", allPlaylists);
        this.setState({
          playlists: allPlaylists
        })
      }
    

    Please help me. I am not able to understand the problem. If I remove withObservables and export as it is, it is working fine.

    opened by YajanaRao 19
  • Is there a way to pause/stop withObservables()

    Is there a way to pause/stop withObservables()

    Is there a way to pause/stop withObservable()? Why? When working with react-navigation, the screen does not get unmounted, which means the withObservable() keeps on running, even if the screen is not focussed anymore. Assuming there are five or six screens connected to a rather large table, this would result in performance issue because all the screens would continiously read from the database (if there are changes), eventhough the screen is not in focus.

    opened by Stophface 0
  • fix(sec): upgrade react-native to 0.64.1

    fix(sec): upgrade react-native to 0.64.1

    What happened?

    There are 1 security vulnerabilities found in react-native 0.63.4

    What did I do?

    Upgrade react-native from 0.63.4 to 0.64.1 for vulnerability fix

    What did you expect to happen?

    Ideally, no insecure libs should be used.

    The specification of the pull request

    PR Specification from OSCS Signed-off-by:pen4[email protected]

    opened by pen4 0
  • Copy type definitions for sync implementation files

    Copy type definitions for sync implementation files

    I'd like to make a custom sync implementation only rewriting the synchronize function to handle pulling changes differently. I believe this will be easily possible but I'm getting a bunch of missing type declaration file errors on imports. I also believe this is what docs meant by keeping your sync impl close to standard watermelondb sync.

    It would be nice if we included these type definition files in the npm package so we can more easily reuse these core functions in our own sync.

    If this isn't the proper way to go about this let me know.

    opened by ChrisSimoniMBT 0
  • Javascript file imports unresolved on webstorm?

    Javascript file imports unresolved on webstorm?

    opened by HyopeR 0
Owner
Nozbe
Powerful to-do app for teams for all the major platforms. Soon introducing all-new Nozbe4.com
Nozbe
MongoDB object modeling designed to work in an asynchronous environment.

Mongoose Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. Mongoose supports both promises and callbacks. Do

Automattic 25.2k Dec 30, 2022
DolphinDB JavaScript API is a JavaScript library that encapsulates the ability to operate the DolphinDB database, such as: connecting to the database, executing scripts, calling functions, uploading variables, etc.

DolphinDB JavaScript API English | 中文 Overview DolphinDB JavaScript API is a JavaScript library that encapsulates the ability to operate the DolphinDB

DolphinDB 6 Dec 12, 2022
Lovefield is a relational database for web apps. Written in JavaScript, works cross-browser. Provides SQL-like APIs that are fast, safe, and easy to use.

Lovefield Lovefield is a relational database written in pure JavaScript. It provides SQL-like syntax and works cross-browser (currently supporting Chr

Google 6.8k Jan 3, 2023
A shopping mobile application made with react native for Android.

Shop App Description This project is a simplified implementation of a shopping system, the project aims to provide the basic features that are expecte

null 114 Dec 26, 2022
Fastify is a web framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture, inspired by Hapi and Express.

Fastify is a web framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture, inspired by Hapi and Express.

Jared Hanson 5 Oct 11, 2022
A simple yet powerful discord.js embed pagination package.

Pagination.djs A discord.js compatible pagination module. It's a simple and lightweight module to paginate discord embeds. Read docs here: pagination.

Parbez 12 Nov 9, 2022
AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.

Please use version 1.x as prior versions has a security flaw if you use user generated data to concat your SQL strings instead of providing them as a

Andrey Gershun 6.1k Jan 9, 2023
Same as sqlite-tag but without the native sqlite3 module dependency

sqlite-tag-spawned Social Media Photo by Tomas Kirvėla on Unsplash The same sqlite-tag ease but without the native sqlite3 dependency, aiming to repla

Andrea Giammarchi 17 Nov 20, 2022
Senior Design Project. Water intake tracker. Software for the communication to bottle and app. Software for app and database

WaterMate Senior Design Project. Water intake tracker to provide everyone with an easy to use water tracking system that can be integrated with your f

null 3 Nov 10, 2021
Fast and advanced, document based and key-value based NoSQL database that able to work as it is installed.

About Fast and advanced, document based and key-value based NoSQL database that able to work as it is installed. Features NoSQL database Can be run as

null 6 Dec 7, 2022
Fast and advanced, document-based and key-value-based NoSQL database.

Contents About Features Installation Links About Fast and advanced, document-based and key-value-based NoSQL database. Features NoSQL database Can be

null 6 Dec 7, 2022
⚡️ lowdb is a small local JSON database powered by Lodash (supports Node, Electron and the browser)

Lowdb Small JSON database for Node, Electron and the browser. Powered by Lodash. ⚡ db.get('posts') .push({ id: 1, title: 'lowdb is awesome'}) .wri

null 18.9k Dec 30, 2022
Execute one command (or mount one Node.js middleware) and get an instant high-performance GraphQL API for your PostgreSQL database!

PostGraphile Instant lightning-fast GraphQL API backed primarily by your PostgreSQL database. Highly customisable and extensible thanks to incredibly

Graphile 11.7k Jan 4, 2023
The JavaScript Database, for Node.js, nw.js, electron and the browser

The JavaScript Database Embedded persistent or in memory database for Node.js, nw.js, Electron and browsers, 100% JavaScript, no binary dependency. AP

Louis Chatriot 13.2k Jan 2, 2023
NodeJS PostgreSQL database performance insights. Locks, index usage, buffer cache hit ratios, vacuum stats and more.

Node Postgres Extras NodeJS port of Heroku PG Extras with several additions and improvements. The goal of this project is to provide powerful insights

Paweł Urbanek 68 Nov 14, 2022
Database manager for MySQL, PostgreSQL, SQL Server, MongoDB, SQLite and others. Runs under Windows, Linux, Mac or as web application

Database manager for MySQL, PostgreSQL, SQL Server, MongoDB, SQLite and others. Runs under Windows, Linux, Mac or as web application

DbGate 2k Dec 30, 2022
An easy-to-use discord bot including database, slash commands and context menus !

Discord Bot Template An easy-to-use discord bot using Discord.JS V13. Wiki Includes: Slash commands Database User commands and more in future Requirem

Gonz 108 Dec 28, 2022
The Blog system developed by nest.js based on node.js and the database orm used typeorm, the development language used TypeScript

考拉的 Nest 实战学习系列 readme 中有很多要说的,今天刚开源还没来及更新,晚些慢慢写,其实本人最近半年多没怎么写后端代码,主要在做低代码和中台么内容,操作的也不是原生数据库而是元数据Meta,文中的原生数据库操作也当作复习下,数据库的操作为了同时适合前端和Node开发小伙伴,所以并不是很

程序员成长指北 148 Dec 22, 2022
Database in JSON, fast and optimize

?? Database-Dev ?? DevNetwork#2103 ?? V 1.0.0 ?? Dependence Libs use ?? NodeJs V 16.14.2 (NodeJs) ?? fs (nodeFS) ?? Use libs import the file in your p

DevNetwork™️ 3 Apr 21, 2022