https://github.com/orbitinghail/libgraft.swift
The Graft SQLite extension packaged for Swift
https://github.com/orbitinghail/libgraft.swift
Last synced: 6 months ago
JSON representation
The Graft SQLite extension packaged for Swift
- Host: GitHub
- URL: https://github.com/orbitinghail/libgraft.swift
- Owner: orbitinghail
- Created: 2025-06-20T00:29:35.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-20T18:17:10.000Z (about 1 year ago)
- Last Synced: 2025-07-19T07:26:06.041Z (about 1 year ago)
- Language: Shell
- Size: 16.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Graft.swift
This repo is a Swift Package Manager (SPM) package to make it easier to use Graft within Swift projects.
## Adding Graft.swift to Your Xcode Project
Follow these steps to add `Graft.swift` to your Xcode project using Swift Package Manager:
1. **Open your Xcode project**.
2. **Go to** `File` > `Add Package Dependencies...`
3. **Enter the repository URL** for `Graft.swift` in the search bar (top right):
```
https://github.com/orbitinghail/Graft.swift.git
```
4. **Select the version** you want to use (usually the latest).
5. **Click "Add Package"**.
6. **Add the Graft "Package Product" to your application target** on the next screen.
7. **Import and initialize the library** during application startup:
```swift
import Foundation
import Graft
// Configure Graft using graft.toml and environment variables
let fm = FileManager.default
let supportDir = try fm.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let configPath = supportDir.appendingPathComponent("graft.toml")
let dataPath = supportDir.appendingPathComponent("graft-data")
// Create a graft.toml configuration file
// See https://graft.rs/docs/sqlite/config/ for all configuration options
let config = """
data_dir = "\(dataPath.path)"
make_default = true
[remote]
type = "memory" // Use "fs" or "s3_compatible" for production
"""
try config.write(to: configPath, atomically: true, encoding: .utf8)
// Set the GRAFT_CONFIG environment variable
setenv("GRAFT_CONFIG", configPath.path, 1)
// Initialize Graft - registers graft with SQLite
try Graft.static_init()
// Now you can use SQLite with Graft pragmas
// See https://graft.rs/docs/sqlite/pragmas/ for available pragmas
```
## Configuration
Graft is configured via a `graft.toml` file. Key configuration options:
- **data_dir**: Where Graft stores local LSM storage data
- **remote**: Configuration for remote object storage (memory, filesystem, or S3-compatible)
- **autosync**: Background synchronization interval in seconds
- **make_default**: Makes Graft VFS the default for new connections
- **log_file**: Path to write verbose operation logs
See the [Graft configuration documentation](https://graft.rs/docs/sqlite/config/) for complete details.
## Using Graft
Once initialized, you can use Graft's custom SQLite pragmas to manage distributed databases:
```sql
PRAGMA graft_new; -- Create a new volume
PRAGMA graft_info; -- Get volume information
PRAGMA graft_push; -- Push local changes to remote
PRAGMA graft_pull; -- Pull and merge remote changes
```
See the [Graft pragmas documentation](https://graft.rs/docs/sqlite/pragmas/) for all available commands.