getObjectBoxModel function

ModelDefinition getObjectBoxModel()

ObjectBox model definition, pass it to Store - Store(getObjectBoxModel())

Implementation

ModelDefinition getObjectBoxModel() {
  final model = ModelInfo(
      entities: _entities,
      lastEntityId: const IdUid(5, 471229950508017654),
      lastIndexId: const IdUid(0, 0),
      lastRelationId: const IdUid(0, 0),
      lastSequenceId: const IdUid(0, 0),
      retiredEntityUids: const [
        4871219055877644958,
        3170801302516940312,
        1463056282138080085
      ],
      retiredIndexUids: const [],
      retiredPropertyUids: const [
        5420264932062407327,
        8312889772924034738,
        1201046228121717544,
        8318909918605768619,
        523235956338335547,
        7010046491295070138,
        1753659186842479407,
        3820146119054923983,
        1288818580948337948,
        4238340144319363592,
        4972912211099811194,
        7455181045514083876,
        8031194273224908966,
        3155884648946248561,
        2390847964259207140,
        7951154263744985103,
        8717053048086099196,
        841540300111972365,
        953506509246344308,
        4544165214297117582,
        5849483025584939680,
        4911809690187606511,
        2185337143616521505,
        6401280775693385501,
        6957991945771947159,
        2035604991037921275,
        1711451347244456241,
        653871223827448058,
        7798459110751191052,
        2490551660392624767,
        6628708505357165366,
        4098534613574496426
      ],
      retiredRelationUids: const [],
      modelVersion: 5,
      modelVersionParserMinimum: 5,
      version: 1);

  final bindings = <Type, EntityDefinition>{
    CacheEntity: EntityDefinition<CacheEntity>(
        model: _entities[0],
        toOneRelations: (CacheEntity object) => [],
        toManyRelations: (CacheEntity object) => {},
        getId: (CacheEntity object) => object.id,
        setId: (CacheEntity object, int id) {
          object.id = id;
        },
        objectToFB: (CacheEntity object, fb.Builder fbb) {
          final expiryTimeOffset = fbb.writeString(object.expiryTime);
          final creationTimeOffset = fbb.writeString(object.creationTime);
          final accessTimeOffset = object.accessTime == null
              ? null
              : fbb.writeString(object.accessTime!);
          final updateTimeOffset = object.updateTime == null
              ? null
              : fbb.writeString(object.updateTime!);
          final keyOffset = fbb.writeString(object.key);
          final valueOffset = fbb.writeListInt8(object.value);
          fbb.startTable(12);
          fbb.addInt64(0, object.id);
          fbb.addOffset(4, expiryTimeOffset);
          fbb.addOffset(5, creationTimeOffset);
          fbb.addOffset(6, accessTimeOffset);
          fbb.addOffset(7, updateTimeOffset);
          fbb.addInt64(8, object.hitCount);
          fbb.addOffset(9, keyOffset);
          fbb.addOffset(10, valueOffset);
          fbb.finish(fbb.endTable());
          return object.id;
        },
        objectFromFB: (Store store, ByteData fbData) {
          final buffer = fb.BufferContext(fbData);
          final rootOffset = buffer.derefObject(0);

          final object = CacheEntity(
              id: const fb.Int64Reader().vTableGet(buffer, rootOffset, 4, 0),
              key: const fb.StringReader(asciiOptimization: true)
                  .vTableGet(buffer, rootOffset, 22, ''),
              value: const fb.Uint8ListReader(lazy: false)
                  .vTableGet(buffer, rootOffset, 24, Uint8List(0)) as Uint8List,
              expiryTime: const fb.StringReader(asciiOptimization: true)
                  .vTableGet(buffer, rootOffset, 12, ''),
              creationTime: const fb.StringReader(asciiOptimization: true)
                  .vTableGet(buffer, rootOffset, 14, ''),
              accessTime: const fb.StringReader(asciiOptimization: true)
                  .vTableGetNullable(buffer, rootOffset, 16),
              updateTime: const fb.StringReader(asciiOptimization: true)
                  .vTableGetNullable(buffer, rootOffset, 18),
              hitCount: const fb.Int64Reader()
                  .vTableGetNullable(buffer, rootOffset, 20));

          return object;
        }),
    VaultEntity: EntityDefinition<VaultEntity>(
        model: _entities[1],
        toOneRelations: (VaultEntity object) => [],
        toManyRelations: (VaultEntity object) => {},
        getId: (VaultEntity object) => object.id,
        setId: (VaultEntity object, int id) {
          object.id = id;
        },
        objectToFB: (VaultEntity object, fb.Builder fbb) {
          final keyOffset = fbb.writeString(object.key);
          final valueOffset = fbb.writeListInt8(object.value);
          final creationTimeOffset = fbb.writeString(object.creationTime);
          final accessTimeOffset = object.accessTime == null
              ? null
              : fbb.writeString(object.accessTime!);
          final updateTimeOffset = object.updateTime == null
              ? null
              : fbb.writeString(object.updateTime!);
          fbb.startTable(7);
          fbb.addInt64(0, object.id);
          fbb.addOffset(1, keyOffset);
          fbb.addOffset(2, valueOffset);
          fbb.addOffset(3, creationTimeOffset);
          fbb.addOffset(4, accessTimeOffset);
          fbb.addOffset(5, updateTimeOffset);
          fbb.finish(fbb.endTable());
          return object.id;
        },
        objectFromFB: (Store store, ByteData fbData) {
          final buffer = fb.BufferContext(fbData);
          final rootOffset = buffer.derefObject(0);

          final object = VaultEntity(
              id: const fb.Int64Reader().vTableGet(buffer, rootOffset, 4, 0),
              key: const fb.StringReader(asciiOptimization: true)
                  .vTableGet(buffer, rootOffset, 6, ''),
              value: const fb.Uint8ListReader(lazy: false)
                  .vTableGet(buffer, rootOffset, 8, Uint8List(0)) as Uint8List,
              creationTime: const fb.StringReader(asciiOptimization: true)
                  .vTableGet(buffer, rootOffset, 10, ''),
              accessTime: const fb.StringReader(asciiOptimization: true)
                  .vTableGetNullable(buffer, rootOffset, 12),
              updateTime: const fb.StringReader(asciiOptimization: true)
                  .vTableGetNullable(buffer, rootOffset, 14));

          return object;
        })
  };

  return ModelDefinition(model, bindings);
}