GRDB.swift

一個專注於應用程式開發的 SQLite 資料庫工具組

GRDB.swift 是什麼?

一個專注於應用程式開發的 SQLite 資料庫工具組。保留品牌名稱、URL、技術術語及事實意義。

GRDB.swift 概覽

這是什麼

GRDB.swift 是一套專注於應用程式開發的 SQLite 資料庫工具組。它提供 SQL 生成、資料庫觀察、穩健的並行處理以及遷移工具,讓開發者能夠在 Swift 中操作 SQLite 資料庫。

主要功能

  • SQL 生成:透過持久化與擷取方法強化應用程式模型,減少直接使用 SQL 的需求。
  • 資料庫觀察:在資料庫值變更時接收通知。
  • 穩健的並行處理:多執行緒應用程式能有效使用資料庫,包括支援並行讀寫的 WAL 資料庫。
  • 遷移:隨著應用程式新版本的發布,演進資料庫結構。
  • 善用 SQLite 技能:支援需要進階 SQLite 功能的開發者。

使用情境

GRDB.swift 適用於在 iOS、macOS、tvOS 和 watchOS 應用程式中將永久資料儲存至 SQLite 資料庫。可用於定義資料庫結構、執行 CRUD 操作、使用 Swift 查詢介面進行查詢,以及觀察資料庫變更。

快速開始

swiftimport GRDB// 1. 開啟資料庫連線let dbQueue = try DatabaseQueue(path: "/path/to/database.sqlite")// 2. 定義資料庫結構try dbQueue.write { db in try db.create(table: "player") { t in t.primaryKey("id", .text) t.column("name", .text).notNull() t.column("score", .integer).notNull() }}// 3. 定義記錄類型struct Player: Codable, Identifiable, FetchableRecord, PersistableRecord { var id: String var name: String var score: Int enum Columns { static let name = Column(CodingKeys.name) static let score = Column(CodingKeys.score) }}// 4. 在資料庫中寫入與讀取try dbQueue.write { db in try Player(id: "1", name: "Arthur", score: 100).insert(db) try Player(id: "2", name: "Barbara", score: 1000).insert(db)}try dbQueue.read { db in let player = try Player.find(db, id: "1") let bestPlayers = try Player .order(score.desc) .limit(10) .fetchAll(db)}

授權與價格

GRDB.swift 是開放原始碼軟體,採用 MIT 授權條款。未提供價格資訊。

內容整理自該專案公開的 README 與儲存庫資訊。

將此徽章加入你的 README

Featured on YunoDB 徽章樣式與說明

你是這個專案的維護者嗎?展示它已收錄於 YunoDB。

Markdown[![Featured on YunoDB](https://yunodb.com/badge/grouegrdbswift.svg)](https://yunodb.com/tools/grouegrdbswift?utm_source=github&utm_medium=badge)
HTML<a href="https://yunodb.com/tools/grouegrdbswift?utm_source=github&utm_medium=badge"><img src="https://yunodb.com/badge/grouegrdbswift.svg" alt="Featured on YunoDB" height="20"></a>