Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for combining this library with realm #1350

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

martinale14
Copy link

No description provided.

@kevmoo
Copy link
Collaborator

kevmoo commented Aug 29, 2023

Uh...I'm excited to see the contribution.

Making something specific to one other framework is less than ideal, but I'm interested in iterating. What are you trying to do here? I don't see any tests or a changelog entry

@martinale14
Copy link
Author

Uh...I'm excited to see the contribution.

Making something specific to one other framework is less than ideal, but I'm interested in iterating. What are you trying to do here? I don't see any tests or a changelog entry

Actually im working on a better solution, im going to update this pr adding some test cases and the changelog, i tried to remove some code to change the core of the package and maintain old implementations

@kevmoo
Copy link
Collaborator

kevmoo commented Aug 29, 2023

Uh...I'm excited to see the contribution.
Making something specific to one other framework is less than ideal, but I'm interested in iterating. What are you trying to do here? I don't see any tests or a changelog entry

Actually im working on a better solution, im going to update this pr adding some test cases and the changelog, i tried to remove some code to change the core of the package and maintain old implementations

I don't like "support realm". That's a bit of a deal breaker. If you could explain what you're trying to do a bit more, I'm happy to discuss!

@martinale14
Copy link
Author

``> > > Uh...I'm excited to see the contribution.

Making something specific to one other framework is less than ideal, but I'm interested in iterating. What are you trying to do here? I don't see any tests or a changelog entry

Actually im working on a better solution, im going to update this pr adding some test cases and the changelog, i tried to remove some code to change the core of the package and maintain old implementations

I don't like "support realm". That's a bit of a deal breaker. If you could explain what you're trying to do a bit more, I'm happy to discuss!

realm is a solution for local and remote db, and also generates a file and it generates with this structure:

@RealmModel()
abstract class _TeacherModel {
  @JsonKey(name: '_id')
  late String id;
  @JsonKey(name: 'name')
  late String name;
  @JsonKey(name: 'last_name')
  late String lastName;
  @JsonKey(name: 'is_active')
  late bool isActive;
  @JsonKey(name: 'age')
  late int age;
  @JsonKey(name: 'is_old')
  late bool? isOld;
}

generates this code:

class TeacherModel extends _TeacherModel
    with RealmEntity, RealmObjectBase, RealmObject {
  TeacherModel(
    ObjectId id,
    String name,
    String lastName,
    bool isActive,
    int age, {
    bool? isOld,
  }) {
    RealmObjectBase.set(this, '_id', id);
    RealmObjectBase.set(this, 'name', name);
    RealmObjectBase.set(this, 'lastName', lastName);
    RealmObjectBase.set(this, 'isActive', isActive);
    RealmObjectBase.set(this, 'age', age);
    RealmObjectBase.set(this, 'isOld', isOld);
  }

  TeacherModel._();

  @override
  ObjectId get id => RealmObjectBase.get<ObjectId>(this, '_id') as ObjectId;
  @override
  set id(ObjectId value) => RealmObjectBase.set(this, '_id', value);

  @override
  String get name => RealmObjectBase.get<String>(this, 'name') as String;
  @override
  set name(String value) => RealmObjectBase.set(this, 'name', value);

  @override
  String get lastName =>
      RealmObjectBase.get<String>(this, 'lastName') as String;
  @override
  set lastName(String value) => RealmObjectBase.set(this, 'lastName', value);

  @override
  bool get isActive => RealmObjectBase.get<bool>(this, 'isActive') as bool;
  @override
  set isActive(bool value) => RealmObjectBase.set(this, 'isActive', value);

  @override
  int get age => RealmObjectBase.get<int>(this, 'age') as int;
  @override
  set age(int value) => RealmObjectBase.set(this, 'age', value);

  @override
  bool? get isOld => RealmObjectBase.get<bool>(this, 'isOld') as bool?;
  @override
  set isOld(bool? value) => RealmObjectBase.set(this, 'isOld', value);

  @override
  Stream<RealmObjectChanges<TeacherModel>> get changes =>
      RealmObjectBase.getChanges<TeacherModel>(this);

  @override
  TeacherModel freeze() => RealmObjectBase.freezeObject<TeacherModel>(this);

  static SchemaObject get schema => _schema ??= _initSchema();
  static SchemaObject? _schema;
  static SchemaObject _initSchema() {
    RealmObjectBase.registerFactory(TeacherModel._);
    return const SchemaObject(
        ObjectType.realmObject, TeacherModel, 'TeacherModel', [
      SchemaProperty('id', RealmPropertyType.objectid,
          mapTo: '_id', primaryKey: true),
      SchemaProperty('name', RealmPropertyType.string),
      SchemaProperty('lastName', RealmPropertyType.string),
      SchemaProperty('isActive', RealmPropertyType.bool),
      SchemaProperty('age', RealmPropertyType.int),
      SchemaProperty('isOld', RealmPropertyType.bool, optional: true),
    ]);
  }
}

but when combining with json serializable this causes an error its that the serializable generates converters for the _TeacherModelClass, so the idea of the pr is to create a flag that allow us to build depending on the realm generated model following the same rules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants