Swift
Adding Graft.swift to Your Xcode Project
Section titled “Adding Graft.swift to Your Xcode Project”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 Foundationimport Graft// Configure Graft using graft.toml and environment variableslet fm = FileManager.defaultlet 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 optionslet 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 variablesetenv("GRAFT_CONFIG", configPath.path, 1)// Initialize Graft - registers graft with SQLitetry Graft.static_init()// Now you can use SQLite with Graft pragmas// See https://graft.rs/docs/sqlite/pragmas/ for available pragmas
Configuration
Section titled “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 configuration documentation for complete details.
Using Graft
Section titled “Using Graft”Once initialized, you can use Graft’s custom SQLite pragmas to manage distributed databases:
PRAGMA graft_new; -- Create a new volumePRAGMA graft_info; -- Get volume informationPRAGMA graft_push; -- Push local changes to remotePRAGMA graft_pull; -- Pull and merge remote changesSee the pragmas documentation for all available commands.