Jaguar-dart / jaguar_orm

Source-generated ORM with relations (one-to-one, one-to-many, many-to-many), preloading, cascading, polymorphic relations, etc
https://jaguar-dart.github.io
BSD 3-Clause "New" or "Revised" License
217 stars 52 forks source link

Implement Custom types #138

Open tejainece opened 5 years ago

pafik13 commented 5 years ago

Hello. Is the task about that?

class A {
  A();

  @PrimaryKey()
  String id;
  String name;

  B b;
}

class B {
  B();

  String field1;
  String field2;
}
tejainece commented 5 years ago

Yes.

It is about "CREATE TYPE" in SQL.

pafik13 commented 5 years ago

Ok

This statement depends on a database. For example, SQLite hasn't it.

tejainece commented 5 years ago

Yes.

It will only be implemented in databases that support it.

tejainece commented 5 years ago

Maybe we can emulate for databases that don't support it.

pafik13 commented 5 years ago

I use flutter with sqfilte package. For the same case I did next steps:

  1. mark field with @IgnoreColumn
  2. generate code
  3. add properties in Bean class with needed columns by scheme ModelPropertyName__NestedClassPropertyName (for the example: b__field1 and b__field2)
  4. add logic into functions: fromMap, toSetColumns and createTable

At the moment I had no problems ;)

Yooooomi commented 4 years ago

Why not just being able to inherit from an abstract type called Serializable which provides String serialization / deserialization ?

Example:

class Stats extends Serializable {
    int points;

    @override
    factory Stats.fromString(String src) {
        // some parsing
    }

    @override
    String toString() {
        // convert to string
    }
}

class User {
    @PrimaryKey(auto: true)
    int id;
    string name;
    Stats stats;
}