Drift Flutter 是一个功能强大的跨平台数据库解决方案,适用于 Flutter 应用程序,可简化 SQLite 数据库的设置和管理。它提供类型安全、响应式的 API 用于查询和修改数据,支持迁移、后台执行和实时更新。基于 Drift 构建,可在 Android、iOS、Web、macOS、Windows 和 Linux 上实现无缝集成。该包通过减少样板代码并为复杂的数据库操作提供直观的语法,提升了开发者的生产力。
适合场景
离线优先的移动应用
实时数据同步
跨平台数据持久化
复杂查询处理
使用本地存储的应用程序状态管理
离线数据缓存
主要特点
类型安全的 SQL 查询
反应式数据库流
自动模式迁移
对多个平台的支持
背景数据库操作
直观的 Dart API
适合对象
开发离线功能的应用程序的开发者
需要跨平台保持一致数据库行为的团队
需要实时数据更新的应用程序
具有复杂数据模型的项目
寻求共享首选项稳健替代方案的Flutter开发者
使用建议
需要理解 SQL 和数据库设计
学习高级功能(如事务)的曲线
由于包含 SQLite,可能会增加应用大小
不太适合简单的键值存储需求
与成熟替代方案相比,文档有限
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Drift
Core
Generator
Drift is a reactive persistence library for Flutter and Dart, built on top of
SQLite.
Drift is:
Flexible: Drift lets you write queries in both SQL and Dart,
providing fluent apis for both languages. You can filter and order results
or use joins to run queries on multiple tables. You can even use complex
SQL features like WITH and WINDOW clauses.
🔥 Feature rich: Drift has builtin support for transactions, schema
migrations, complex filters and expressions, batched updates and joins. We
even have a builtin IDE for SQL!
📦 Modular: Thanks to builtin support for daos and imports in SQL files, drift helps you keep your database code simple.
🛡️ Safe: Drift generates type-safe code based on your tables and queries. If you make a mistake in your queries, drift will find it at compile time and
provide helpful and descriptive lints.
⚡ Fast: Even though drift lets you write powerful queries, it can keep
up with the performance of key-value stores like shared preferences and Hive. Drift is the only major persistence library with builtin threading support, allowing you to run database code across isolates with zero additional effort.
Reactive: Turn any SQL query into an auto-updating stream! This includes complex queries across many tables.
⚙️ Cross-Platform support: Drift works on Android, iOS, macOS, Windows, Linux and the web. This template is a Flutter todo app that works on all platforms.
🗡️ Battle tested and production ready: Drift is stable and well tested with a wide range of unit and integration tests. It powers production Flutter apps.
This repository contains a number of packages making up the drift project, most
notably:
drift: The main runtime for drift, which provides most APIs.
drift_dev: The compiler for drift tables, databases and daos. It
also contains a fully-featured SQL IDE for the Dart analyzer.
sqlparser: A SQL parser and static analyzer, written in pure Dart. This package can be used without drift to perform analysis on SQL statements.
It's on pub at
.
We use melos to manage the different packages
in this repository.
You can install it with dart pub global activate melos. To activate it in this
repository, run dart pub get in this directory followed by melos bootstrap.