WatermelonDB

Reactive & asynchronous database for powerful React and React Native apps

README

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


|
-
⚡️
📈
😎
🔄
📱
⚛️
🧰
🔗
⚠️

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](https://www.youtube.com/watch?v=UlZ1QnFF4Cw).

-------

Usage


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

First, you define Models:

  1. ``` js
  2. class Post extends Model {
  3.   @field('name') name
  4.   @field('body') body
  5.   @children('comments') comments
  6. }

  7. class Comment extends Model {
  8.   @field('body') body
  9.   @field('author') author
  10. }
  11. ```

Then, you connect components to the data:

  1. ``` js
  2. const Comment = ({ comment }) => (
  3.   <View style={styles.commentBox}>
  4.     <Text>{comment.body} by {comment.author}</Text>
  5.   </View>
  6. )

  7. // This is how you make your app reactive! ✨
  8. const enhance = withObservables(['comment'], ({ comment }) => ({
  9.   comment,
  10. }))
  11. const EnhancedComment = enhance(Comment)
  12. ```

And now you can render the whole Post:

  1. ``` js
  2. const Post = ({ post, comments }) => (
  3.   <View>
  4.     <Text>{post.name}</Text>
  5.     <Text>Comments:</Text>
  6.     {comments.map(comment =>
  7.       <EnhancedComment key={comment.id} comment={comment} />
  8.     )}
  9.   </View>
  10. )

  11. const enhance = withObservables(['post'], ({ post }) => ({
  12.   post,
  13.   comments: post.comments
  14. }))
  15. ```

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
Chatable
Todorant
Blast Workout

_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.

WatermelonDB's main author and maintainer is Radek Pietruszewski (websitetwitterengineering posters)


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