A document database with the typesafety and ease of use you want and the querying and indexing that you need.
- Store data without defining schemas, tables or object models
- The typesafety you're used to with Swift (No vars, forced unwrapping, casting or NSObjects)
- Indexing makes efficient sorting and filtering possible
- Non-blocking operations that run on a background thread by default
- 100% client side, free to use open source database under MIT license
struct TodoItem: Document, Codable {
static let documentDescriptor = DocumentDescriptor<TodoItem>(name: "TodoItem",
identifier: Identifier(keyPath: \.id),
indices: [
Index(name: "completed", keyPath: \.completed)
])
let id: Int
let text: String
let completed: Bool
}
let documentStore = try DocumentStore(identifier: "TodoStore",
documentDescriptors: [TodoItem.documentDescriptor])
let todoItem = TodoItem(id: 1, text: "Give DocumentStore a try", completed: false)
documentStore.write(handler: { result in
if case let .failure(error) = result {
fatalError(error)
}
}, actions: { transaction in
try transaction.insert(document: todoItem)
return .saveChanges
})
let uncompletedQuery = Query<TodoItem>()
.sorted(by: \.id, order: .ascending)
.filtered { _ in !\.completed }
documentStore.read(handler: { result in
switch result {
case let .success(todoItems):
debugPrint(todoItems)
case let .failure(error):
fatalError(error)
}
}, actions: { transaction in
try transaction.fetch(matching: uncompletedQuery)
})
DocumentStore is a good fit when you want to:
- persist items to disk
- be able to sort and filter them
- ease of use
TODO: Explain ways to use this in your project.
DocumentStore has no hard limits and is optimized for a few thousands of objects that are small to medium sized (up to ±1MB). Very big objects or a big number of documents may start to slow things down.
DocumentStore is created by Mathijs Kadijk and released under a MIT License.