搜尋套件、儲存庫與 APP 分類

套件詳情v0.0.6+6

quds_db

一個 sqflite 擴展套件,可簡化建立資料庫和資料表、CRUD 操作及帶模型化的查詢

AndroidiOSmacOSWindowsLinux
近 30 天下載
8
喜歡數
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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。