搜索插件、代码仓与 APP 分类

插件详情v0.0.6+6

quds_db

一个 sqflite 扩展包,可简化创建数据库和表、CRUD 操作以及带建模的查询

AndroidiOSmacOSWindowsLinux
近 30 天下载
16
喜欢数
33
Pub 分数
140

安装插件

flutter pub add quds_db

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

quds_db 是一个 Flutter/Dart 包,扩展了 sqflite 以简化数据库管理。它简化了数据库和表的创建,支持 CRUD 操作,并可实现基于模型的查询。通过抽象复杂的 SQL 逻辑,使开发者能够使用 Dart 模型操作结构化数据,减少样板代码。该包旨在跨多个平台实现与本地 SQLite 数据库的高效、类型安全的交互。

适合场景

  • 移动应用中的本地数据持久化
  • 使用模型简化 CRUD 操作
  • 构建离线优先的应用程序
  • 管理结构化应用数据
  • 简化数据库设置和迁移

主要特点

  • 模型驱动的数据库操作
  • 内置的 CRUD 方法
  • 从模型自动创建表格
  • 支持带有模型映射的复杂查询
  • 跨平台 SQLite 集成

适合对象

  • 寻求 sqflite 简化的开发者
  • 需要本地数据库存储的项目
  • 需要离线功能的应用
  • 优先考虑代码可读性的团队
  • 带有结构化数据的Flutter应用需要

使用建议

  • 需要了解 sqflite 的基础知识
  • 仅限 SQLite 数据库后端
  • 可能需要额外设置才能进行高级查询
  • 依赖于正确的模型类定义
  • 不适用于基于云或实时数据

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Quds Db

Is an automated version of sqflite!

How to use

1. To create a model

Model classes should extend DbModel class. Define the schema of your model, Supported field type:

Integers Strings DateTimes Others
IdField StringField DateTimeField (saved as num) BlobField
IntField DateTimeStringField (Saved as string) BoolField
NumField JsonField
ListField
DoubleField ColorField
EnumField
class Note extends DbModel {
  var title = StringField(columnName: 'title');
  var content = StringField(columnName: 'content');
  var isImportant = BoolField(columnName: 'isImportant');
  var color = ColorField(columnName: 'color');

  @override
  List<FieldWithValue>? getFields() => [title, content, isImportant, color];
}

Note that: Every model has default fields:

  • id (Auto incremental integer field)
  • creationTime (automatically set once when created)
  • modificationTime (automatically set when created, and with every update operation)

2. To create a table manager
class NotesProvider extends DbTableProvider<Note> {
  NotesProvider() : super(() => Note());

  @override
  String get tableName => 'Notes';
}

As shown, to set the name of the table:

  @override
  String get tableName => 'Notes';

Note that: In provider class constructor, you should provide it with model object creation function.

  NotesProvider() : super(() => Note());

To create a provider instance,

NotesProvider notesProvider = NotesProvider();
3. Crud operations:
Creation: (Insertion)

single:

    Note n = Note();
    n.title.value = 'New note';
    n.content.value = 'Note content, describe your self';
    n.isImportant.value = ([true, false]..shuffle()).first;
    n.color.value = ([Colors.red, Colors.blue, Colors.yellow, Colors.orange]
          ..shuffle())
        .first;

    await notesProvider.insertEntry(n);

multiple:

    await notesProvider.insertCollection([n1,n2,n3,...]);
Reading (Query):
var allNotes = await notesProvider.select();
var importantNotes = await notesProvider.select(where:(n)=>n.isImportant.isTrue);
var imortantRed = await notesProvider.select(where:(n)=>n.isImportant.isTrue & n.color.equals(Color(0xffff0000)));
Updating:
n.title = 'new title';
await notesProvider.updateEntry(n);
Deletion:
await notesProvider.deleteEntry(n);

Monitoring changes:

To handle the changes in some table:

  notesProvider.addEntryChangeListner((changeType, entry) {
      switch (changeType) {
        case EntryChangeType.Insertion:
          //New Note added (entry)
          break;
        case EntryChangeType.Deletion:
          //(entry) has been deleted
          break;
        case EntryChangeType.Modification:
          //(entry) has been modified
          break;
      }
    });

Database location:

Where are the data being stored? By default, your data will be saved in app data folder / 'data.db', and to change it:

  DbHelper.mainDbPath = 'your db path';

And if you want to save a table in other file:

class NotesProvider extends DbTableProvider<Note> {
  NotesProvider()
      : super(() => Note(), specialDbFile: 'your specified file path');

  @override
  String get tableName => 'Notes';
}

所属分类

依赖

依赖清单 7 项

源码仓库

使用此插件的项目

暂无相关数据。