About ObjectiveRecord
ObjectiveRecord is a lightweight Swift library that provides a simple and intuitive way to work with SQLite databases. It aims to simplify database operations by providing a wrapper around SQLite’s C API, while still offering flexibility and performance.
Features
- Easy setup and configuration
- Simple syntax for creating, querying, and updating SQLite databases
- Support for CRUD operations (Create, Read, Update, Delete) on database objects
- Efficient relationship management between database tables
- Automatic schema migrations and versioning
- Seamless integration with Swift’s native types and protocols
- Lightweight and optimized for performance
Installation
To install ObjectiveRecord, follow these steps:
- Open your project in Xcode.
- Navigate to your project’s target settings.
- Go to the “General” tab.
- Scroll down to the “Frameworks, Libraries, and Embedded Content” section.
- Click the “+” button to add a new framework or library.
- Search for “ObjectiveRecord” and select it from the search results.
- Click “Add” to add the ObjectiveRecord library to your project.
Usage
ObjectiveRecord provides a clean and intuitive API for working with SQLite databases. Here are some examples of common usage:
Setup and Configuration
Before using ObjectiveRecord, you need to set up the database connection. Typically, this is done in the AppDelegate
class of your application:
import ObjectiveRecord
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Set up the database connection
let databaseURL = // TODO: Specify the URL of your SQLite database file
ActiveRecord.setup(databaseURL: databaseURL)
return true
}
Creating a Database Object
To create a new object in your database, you can simply create a new instance of your model class and save it:
let user = User()
user.name = "John Doe"
user.age = 30
user.save()
Querying the Database
You can use ObjectiveRecord’s expressive syntax to query your database:
let users = User.where(column: "age", isGreaterThan: 25).orderBy(column: "name", ascending: true).limit(10).all()
Updating a Database Object
Updating an object in the database is straightforward. Simply modify the properties of your object and save it:
let user = User.find(1)
user.name = "Updated Name"
user.save()
Deleting a Database Object
To delete an object from the database, use the delete()
method:
let user = User.find(1)
user.delete()
Relationships
ObjectiveRecord supports relationships between database tables. You can define relationships using Swift properties:
class User: ActiveRecord {
var pets: [Pet] {
return hasMany(Pet.self)
}
}
Schema Migrations
ObjectiveRecord handles schema migrations automatically. Simply update your model classes to reflect changes in the database schema, and ObjectiveRecord will take care of migrating existing data:
class User: ActiveRecord {
var name: String = ""
var age: Int = 0
var email: String = ""
override class var schemaVersion: UInt64 {
return 2
}
override class func schemaMigration() {
// Perform any necessary migrations here
}
}
Contributing
If you’d like to contribute to ObjectiveRecord, please follow these guidelines:
- Fork the repository
- Create a new branch for your changes
- Make your modifications
- Submit a pull request
License
ObjectiveRecord is released under the MIT License. See the LICENSE file for details.
Contact
If you have any questions, suggestions, or bug reports, please contact us at info@objectiverecord.com.