Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0xleif/flite
FLite is a streamlined Swift ORM for using FluentSQLiteDriver
https://github.com/0xleif/flite
async-await database fluent ios macos sqlite swift tvos watchos
Last synced: 2 months ago
JSON representation
FLite is a streamlined Swift ORM for using FluentSQLiteDriver
- Host: GitHub
- URL: https://github.com/0xleif/flite
- Owner: 0xLeif
- License: mit
- Created: 2023-08-11T17:36:19.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-24T00:52:23.000Z (over 1 year ago)
- Last Synced: 2024-05-02T06:02:20.945Z (8 months ago)
- Topics: async-await, database, fluent, ios, macos, sqlite, swift, tvos, watchos
- Language: Swift
- Homepage: https://flite.0xl.io/
- Size: 15.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# FLite
*FLite is a streamlined Swift ORM for using [FluentSQLiteDriver](https://github.com/vapor/fluent-sqlite-driver) on iOS, macOS, watchOS, and tvOS applications.*
## What is FLite?
FLite is a Swift library that simplifies usage of FluentSQLiteDriver across various Apple platforms. It takes full advantage of Swift's strong type system and modern concurrency features to provide an easy-to-use interface for database management.
## Features
- Powered by FluentSQLiteDriver.
- Simplified access to in-memory and SQLite database functionality.
- Clean and intuitive APIs for database operations.
- Non-blocking asynchronous methods that align with Swift's concurrency model for optimal performance.
- Comprehensive support for database schema migrations.
- Type-safe approach for building and executing database queries.## Installation
### Swift Package Manager (SPM)
Add the following line to your Package.swift file in the dependencies array:
```swift
dependencies: [
.package(url: "https://github.com/0xLeif/FLite.git", from: "1.0.0")
]
```## Usage
Firstly, be sure to import FLite in your file:
```swift
import FLite
```### Basic Usage
```swift
// Use FLite's shared memory singleton as our FLite database
let flite = FLite.memory// Prepare a migration for a Todo model
try await flite.prepare(migration: Todo.self)// Save a model instance to the database
try await flite.save(model: Todo(title: "Hello World", strings: ["hello", "world"]))// Fetch all instances of our model
let todos = try await flite.all(model: Todo.self)
print(todos)
```### File Storage
```swift
let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path ?? ""
let fileURL = documentDirectory + "/default.sqlite"let flite = FLite(configuration: .file(fileURL), loggerLabel: "Custom.FLite")
```### Batch Operations
```swift
let batchSize: UInt = 3let todos = (0..<100).map { Todo(title: "Todo #\($0)", strings: []) }
try await flite.save(models: todos, batchSize: batchSize)let allTodos = try await flite.all(model: Todo.self)
print("Saved \(allTodos.count) todos")try await flite.deleteAll(model: Todo.self, batchSize: batchSize)
```## Contributing
FLite encourages community involvement and welcomes pull requests from experienced and first-time contributors. For bugs and feature requests, please create an issue.
## License
FLite is released under the MIT License. See `LICENSE` for details.