This repo is a Swift Package Manager (SPM) package to make it easier to use Graft within Swift projects.
Follow these steps to add Graft.swift to your Xcode project using Swift Package Manager:
-
Open your Xcode project.
-
Go to
File>Add Package Dependencies... -
Enter the repository URL for
Graft.swiftin the search bar (top right):https://github.com/orbitinghail/Graft.swift.git -
Select the version you want to use (usually the latest).
-
Click "Add Package".
-
Add the Graft "Package Product" to your application target on the next screen.
-
Import and initialize the library during application startup:
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
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 for complete details.
Once initialized, you can use Graft's custom SQLite pragmas to manage distributed databases:
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 changesSee the Graft pragmas documentation for all available commands.