SQLiteService
It is a library for easier and type-safe use of sqlite in the apple device(ios/macos) environment.
Installation
Currently, only SPM is supported.
How to use it
The interface of SQLiteService simply consists of open/close + run + migration. The operation that returns the Result type is synchronous, and when the Result is passed to the completion handler, it operates asynchronously. (Synchronous operations of asynchronous operation + run action are executed after the migration operation is finished internally in SQLiteService.)
The run method should be called with a closure of this type: (DataBase) throws -> T
indicating what action to take and what the result type is. (DataBase)
follows the Connection & DataBase
protocol. Please refer to the protocol for which functions are supported. (Instead of using SQLiteService, you can directly handle SQLiteDataBase
objects that conforms the Connection & DataBase
protocol.)
open and close database
Table
Table
must be defined with ColumnType
and EntityType
.
Use ColumnType
to specify the column name and stored data type.
EntityType
must conform to RowValueType
, which means that the query result can be returned as a data model.
Below are examples of UserTable
and PetTable
that store user and pet information.
Another requirement for tables is to indicate which property of the entity matches each column using the static func scalar(_ entity: Entity, for column: Columns) -> ScalarType?
type method.
(Actual data is stored by matching entity property values according to the order of columns following the CaseIterable
protocol.)
data manipulation
Here are some basic data manipulation usages.
For more information on how to use it, see unit tests.
As you can see from the readme, this project has a lot of missing features and a lot of room for improvement. Feedback or contributions to the project are always welcome. ?