WatermelonDB 下一代 React 数据库

程序名称:WatermelonDB

授权协议: MIT

操作系统: 跨平台

开发语言: Objective-C

WatermelonDB 介绍

WatermelonDB,下一代 React 数据库,可构建功能强大的 React 和 React Native
应用程序,可在保持快速的同时从数百个记录扩展到数万个记录。

WatermelonDB 是一种在 React Native 和 React Web 应用中处理用户数据的新方法。它针对在 React/React
Native 中构建复杂应用进行优化,其首要目标是提高实际性能。简单来说,就是保证的的应用必须快速启动。

当你开始扩展到数千或数万个数据库记录时,会发现对应用的启动速度有很大影响,尤其是在速度较慢的 Android 设备上。WatermelonDB
通过惰性(lazy)来解决问题 —— 除非有要求,否则不加载。而且由于所有查询都是直接以单独的线程在稳定的 SQLite 数据库上执行的,所以即使是在较慢的
Android 设备上,多数查询也会在不到1毫秒的时间内解析,即使有 10,000 条记录!

Usage

首先,定义模型

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

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

然后,将组件与数据连接:

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: comment.observe()
}))
const EnhancedComment = enhance(Comment)

即可进行渲染

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: post.observe(),
  comments: post.comments.observe()
}))

WatermelonDB 官网

https://github.com/Nozbe/WatermelonDB

相关编程语言

BBGestureBack Full screen return gesture(全屏手...
Framework7 或者叫 F7 是全功能的绑定 iOS 7 应用的...
iOS 调试库,支持 iOS8+,无需添加任何代码,方便 i...
DarkModeKit是在Apple官方的深色模式发布之前设计和...
SimpleNote iOS 版客户端。SimpleNote 是一款在多平...
Kivy iOS,此工具旨在为 iOS 编译必要的库以运行应用...