-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8f0fba
commit d09c2d0
Showing
26 changed files
with
1,801 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule objectbox-swift-generator
updated
10 files
+2 −1 | .swiftlint.yml | |
+18 −18 | ObjectBox/BuildTracker.swift | |
+1 −0 | ObjectBox/EntityInfo.stencil | |
+140 −150 | ObjectBox/IdSyncModel.swift | |
+22 −23 | ObjectBox/IdSyncModelTests.swift | |
+55 −47 | ObjectBox/ObjectBoxGenerator.swift | |
+10 −10 | ObjectBox/PrettyJSON.swift | |
+66 −89 | ObjectBox/Schema.swift | |
+1 −1 | ObjectBox/sha1.swift | |
+1 −1 | SourceryUtils/Sources/Version.swift |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
298 changes: 298 additions & 0 deletions
298
Source/ios-framework/CodeGenTests/expected/entity-info/EntityInfo.generated36.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,298 @@ | ||
// Generated using the ObjectBox Swift Generator — https://objectbox.io | ||
// DO NOT EDIT | ||
|
||
// swiftlint:disable all | ||
import ObjectBox | ||
import Foundation | ||
|
||
// MARK: - Entity metadata | ||
|
||
|
||
extension Author: ObjectBox.__EntityRelatable { | ||
internal typealias EntityType = Author | ||
|
||
internal var _id: EntityId<Author> { | ||
return EntityId<Author>(self.id.value) | ||
} | ||
} | ||
|
||
extension Author: ObjectBox.EntityInspectable { | ||
internal typealias EntityBindingType = AuthorBinding | ||
|
||
/// Generated metadata used by ObjectBox to persist the entity. | ||
internal static var entityInfo = ObjectBox.EntityInfo(name: "Author", id: 1) | ||
|
||
internal static var entityBinding = EntityBindingType() | ||
|
||
fileprivate static func buildEntity(modelBuilder: ObjectBox.ModelBuilder) throws { | ||
let entityBuilder = try modelBuilder.entityBuilder(for: Author.self, id: 1, uid: 16640) | ||
try entityBuilder.addProperty(name: "id", type: PropertyType.long, flags: [.id], id: 1, uid: 14592) | ||
try entityBuilder.addProperty(name: "name", type: PropertyType.string, id: 2, uid: 15616) | ||
|
||
try entityBuilder.lastProperty(id: 2, uid: 15616) | ||
} | ||
} | ||
|
||
extension Author { | ||
/// Generated entity property information. | ||
/// | ||
/// You may want to use this in queries to specify fetch conditions, for example: | ||
/// | ||
/// box.query { Author.id == myId } | ||
internal static var id: Property<Author, EntityId<Author>, EntityId<Author>> { return Property<Author, EntityId<Author>, EntityId<Author>>(propertyId: 1, isPrimaryKey: true) } | ||
/// Generated entity property information. | ||
/// | ||
/// You may want to use this in queries to specify fetch conditions, for example: | ||
/// | ||
/// box.query { Author.name.startsWith("X") } | ||
internal static var name: Property<Author, String, Void> { return Property<Author, String, Void>(propertyId: 2, isPrimaryKey: false) } | ||
|
||
fileprivate func __setId(identifier: ObjectBox.Id) { | ||
self.id = EntityId(identifier) | ||
} | ||
} | ||
|
||
extension ObjectBox.Property where E == Author { | ||
/// Generated entity property information. | ||
/// | ||
/// You may want to use this in queries to specify fetch conditions, for example: | ||
/// | ||
/// box.query { .id == myId } | ||
|
||
internal static var id: Property<Author, EntityId<Author>, EntityId<Author>> { return Property<Author, EntityId<Author>, EntityId<Author>>(propertyId: 1, isPrimaryKey: true) } | ||
|
||
/// Generated entity property information. | ||
/// | ||
/// You may want to use this in queries to specify fetch conditions, for example: | ||
/// | ||
/// box.query { .name.startsWith("X") } | ||
|
||
internal static var name: Property<Author, String, Void> { return Property<Author, String, Void>(propertyId: 2, isPrimaryKey: false) } | ||
|
||
} | ||
|
||
|
||
/// Generated service type to handle persisting and reading entity data. Exposed through `Author.EntityBindingType`. | ||
internal class AuthorBinding: ObjectBox.EntityBinding { | ||
internal typealias EntityType = Author | ||
internal typealias IdType = EntityId<Author> | ||
|
||
internal required init() {} | ||
|
||
internal func generatorBindingVersion() -> Int { 1 } | ||
|
||
internal func setEntityIdUnlessStruct(of entity: EntityType, to entityId: ObjectBox.Id) { | ||
entity.__setId(identifier: entityId) | ||
} | ||
|
||
internal func entityId(of entity: EntityType) -> ObjectBox.Id { | ||
return entity.id.value | ||
} | ||
|
||
internal func collect(fromEntity entity: EntityType, id: ObjectBox.Id, | ||
propertyCollector: ObjectBox.FlatBufferBuilder, store: ObjectBox.Store) throws { | ||
let propertyOffset_name = propertyCollector.prepare(string: entity.name) | ||
|
||
propertyCollector.collect(id, at: 2 + 2 * 1) | ||
propertyCollector.collect(dataOffset: propertyOffset_name, at: 2 + 2 * 2) | ||
} | ||
|
||
internal func createEntity(entityReader: ObjectBox.FlatBufferReader, store: ObjectBox.Store) -> EntityType { | ||
let entity = Author() | ||
|
||
entity.id = entityReader.read(at: 2 + 2 * 1) | ||
entity.name = entityReader.read(at: 2 + 2 * 2) | ||
|
||
return entity | ||
} | ||
} | ||
|
||
|
||
|
||
extension Book: ObjectBox.__EntityRelatable { | ||
internal typealias EntityType = Book | ||
|
||
internal var _id: EntityId<Book> { | ||
return EntityId<Book>(self.id.value) | ||
} | ||
} | ||
|
||
extension Book: ObjectBox.EntityInspectable { | ||
internal typealias EntityBindingType = BookBinding | ||
|
||
/// Generated metadata used by ObjectBox to persist the entity. | ||
internal static var entityInfo = ObjectBox.EntityInfo(name: "Book", id: 2) | ||
|
||
internal static var entityBinding = EntityBindingType() | ||
|
||
fileprivate static func buildEntity(modelBuilder: ObjectBox.ModelBuilder) throws { | ||
let entityBuilder = try modelBuilder.entityBuilder(for: Book.self, id: 2, uid: 20736) | ||
try entityBuilder.addProperty(name: "id", type: PropertyType.long, flags: [.id], id: 1, uid: 17664) | ||
try entityBuilder.addProperty(name: "name", type: PropertyType.string, id: 2, uid: 18688) | ||
try entityBuilder.addToManyRelation(id: 1, uid: 19712, | ||
targetId: 1, targetUid: 16640) | ||
|
||
try entityBuilder.lastProperty(id: 2, uid: 18688) | ||
} | ||
} | ||
|
||
extension Book { | ||
/// Generated entity property information. | ||
/// | ||
/// You may want to use this in queries to specify fetch conditions, for example: | ||
/// | ||
/// box.query { Book.id == myId } | ||
internal static var id: Property<Book, EntityId<Book>, EntityId<Book>> { return Property<Book, EntityId<Book>, EntityId<Book>>(propertyId: 1, isPrimaryKey: true) } | ||
/// Generated entity property information. | ||
/// | ||
/// You may want to use this in queries to specify fetch conditions, for example: | ||
/// | ||
/// box.query { Book.name.startsWith("X") } | ||
internal static var name: Property<Book, String, Void> { return Property<Book, String, Void>(propertyId: 2, isPrimaryKey: false) } | ||
/// Use `Book.authors` to refer to this ToMany relation property in queries, | ||
/// like when using `QueryBuilder.and(property:, conditions:)`. | ||
|
||
internal static var authors: ToManyProperty<Author> { return ToManyProperty(.relationId(1)) } | ||
|
||
|
||
fileprivate func __setId(identifier: ObjectBox.Id) { | ||
self.id = EntityId(identifier) | ||
} | ||
} | ||
|
||
extension ObjectBox.Property where E == Book { | ||
/// Generated entity property information. | ||
/// | ||
/// You may want to use this in queries to specify fetch conditions, for example: | ||
/// | ||
/// box.query { .id == myId } | ||
|
||
internal static var id: Property<Book, EntityId<Book>, EntityId<Book>> { return Property<Book, EntityId<Book>, EntityId<Book>>(propertyId: 1, isPrimaryKey: true) } | ||
|
||
/// Generated entity property information. | ||
/// | ||
/// You may want to use this in queries to specify fetch conditions, for example: | ||
/// | ||
/// box.query { .name.startsWith("X") } | ||
|
||
internal static var name: Property<Book, String, Void> { return Property<Book, String, Void>(propertyId: 2, isPrimaryKey: false) } | ||
|
||
/// Use `.authors` to refer to this ToMany relation property in queries, like when using | ||
/// `QueryBuilder.and(property:, conditions:)`. | ||
|
||
internal static var authors: ToManyProperty<Author> { return ToManyProperty(.relationId(1)) } | ||
|
||
} | ||
|
||
|
||
/// Generated service type to handle persisting and reading entity data. Exposed through `Book.EntityBindingType`. | ||
internal class BookBinding: ObjectBox.EntityBinding { | ||
internal typealias EntityType = Book | ||
internal typealias IdType = EntityId<Book> | ||
|
||
internal required init() {} | ||
|
||
internal func generatorBindingVersion() -> Int { 1 } | ||
|
||
internal func setEntityIdUnlessStruct(of entity: EntityType, to entityId: ObjectBox.Id) { | ||
entity.__setId(identifier: entityId) | ||
} | ||
|
||
internal func entityId(of entity: EntityType) -> ObjectBox.Id { | ||
return entity.id.value | ||
} | ||
|
||
internal func collect(fromEntity entity: EntityType, id: ObjectBox.Id, | ||
propertyCollector: ObjectBox.FlatBufferBuilder, store: ObjectBox.Store) throws { | ||
let propertyOffset_name = propertyCollector.prepare(string: entity.name) | ||
|
||
propertyCollector.collect(id, at: 2 + 2 * 1) | ||
propertyCollector.collect(dataOffset: propertyOffset_name, at: 2 + 2 * 2) | ||
} | ||
|
||
internal func postPut(fromEntity entity: EntityType, id: ObjectBox.Id, store: ObjectBox.Store) throws { | ||
if entityId(of: entity) == 0 { // New object was put? Attach relations now that we have an ID. | ||
let authors = ToMany<Author>.relation( | ||
sourceId: EntityId<Book>(id.value), | ||
targetBox: store.box(for: ToMany<Author>.ReferencedType.self), | ||
relationId: 1) | ||
if !entity.authors.isEmpty { | ||
authors.replace(entity.authors) | ||
} | ||
entity.authors = authors | ||
try entity.authors.applyToDb() | ||
} | ||
} | ||
internal func createEntity(entityReader: ObjectBox.FlatBufferReader, store: ObjectBox.Store) -> EntityType { | ||
let entity = Book() | ||
|
||
entity.id = entityReader.read(at: 2 + 2 * 1) | ||
entity.name = entityReader.read(at: 2 + 2 * 2) | ||
|
||
entity.authors = ToMany<Author>.relation( | ||
sourceId: EntityId<Book>(entity.id.value), | ||
targetBox: store.box(for: ToMany<Author>.ReferencedType.self), | ||
relationId: 1) | ||
return entity | ||
} | ||
} | ||
|
||
|
||
/// Helper function that allows calling Enum(rawValue: value) with a nil value, which will return nil. | ||
fileprivate func optConstruct<T: RawRepresentable>(_ type: T.Type, rawValue: T.RawValue?) -> T? { | ||
guard let rawValue = rawValue else { return nil } | ||
return T(rawValue: rawValue) | ||
} | ||
|
||
// MARK: - Store setup | ||
|
||
fileprivate func cModel() throws -> OpaquePointer { | ||
let modelBuilder = try ObjectBox.ModelBuilder() | ||
try Author.buildEntity(modelBuilder: modelBuilder) | ||
try Book.buildEntity(modelBuilder: modelBuilder) | ||
modelBuilder.lastEntity(id: 2, uid: 20736) | ||
modelBuilder.lastRelation(id: 1, uid: 19712) | ||
return modelBuilder.finish() | ||
} | ||
|
||
extension ObjectBox.Store { | ||
/// A store with a fully configured model. Created by the code generator with your model's metadata in place. | ||
/// | ||
/// # In-memory database | ||
/// To use a file-less in-memory database, instead of a directory path pass `memory:` | ||
/// together with an identifier string: | ||
/// ```swift | ||
/// let inMemoryStore = try Store(directoryPath: "memory:test-db") | ||
/// ``` | ||
/// | ||
/// - Parameters: | ||
/// - directoryPath: The directory path in which ObjectBox places its database files for this store, | ||
/// or to use an in-memory database `memory:<identifier>`. | ||
/// - maxDbSizeInKByte: Limit of on-disk space for the database files. Default is `1024 * 1024` (1 GiB). | ||
/// - fileMode: UNIX-style bit mask used for the database files; default is `0o644`. | ||
/// Note: directories become searchable if the "read" or "write" permission is set (e.g. 0640 becomes 0750). | ||
/// - maxReaders: The maximum number of readers. | ||
/// "Readers" are a finite resource for which we need to define a maximum number upfront. | ||
/// The default value is enough for most apps and usually you can ignore it completely. | ||
/// However, if you get the maxReadersExceeded error, you should verify your | ||
/// threading. For each thread, ObjectBox uses multiple readers. Their number (per thread) depends | ||
/// on number of types, relations, and usage patterns. Thus, if you are working with many threads | ||
/// (e.g. in a server-like scenario), it can make sense to increase the maximum number of readers. | ||
/// Note: The internal default is currently around 120. So when hitting this limit, try values around 200-500. | ||
/// - readOnly: Opens the database in read-only mode, i.e. not allowing write transactions. | ||
/// | ||
/// - important: This initializer is created by the code generator. If you only see the internal `init(model:...)` | ||
/// initializer, trigger code generation by building your project. | ||
internal convenience init(directoryPath: String, maxDbSizeInKByte: UInt64 = 1024 * 1024, | ||
fileMode: UInt32 = 0o644, maxReaders: UInt32 = 0, readOnly: Bool = false) throws { | ||
try self.init( | ||
model: try cModel(), | ||
directory: directoryPath, | ||
maxDbSizeInKByte: maxDbSizeInKByte, | ||
fileMode: fileMode, | ||
maxReaders: maxReaders, | ||
readOnly: readOnly) | ||
} | ||
} | ||
|
||
// swiftlint:enable all |
Oops, something went wrong.