-
Because drifts model generation is very convenient and I have been ignoring it in favour of my own freezed classes, However, I cannot figure out how I could generate a model that is the result of a join. class DungeonsTable extends Table {
IntColumn get id => integer().autoIncrement()();
}
class BossRoomsTable extends Table {
IntColumn get id =>
integer().references(DungeonsTable, #id, onDelete: KeyAction.cascade)();
IntColumn get boss => integer()();
}
class Boss extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get name => text()();
TextColumn get description => text()();
TextColumn get image => text()();
}
class TreasuresRoomTable extends Table {
IntColumn get id =>
integer().references(DungeonsTable, #id, onDelete: KeyAction.cascade)();
IntColumn get treasure => integer()();
}
class Treasure extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get name => text()();
TextColumn get description => text()();
TextColumn get image => text()();
} now it would be really nice if I could automatically generate a class like class Dungeon {
final BossRoom bossRoom;
final TreasureRoom treasureRoom;
}
class BossRoom {
final Boss boss;
}
class TreasureRoom {
final Treasure treasure;
} which are essentially just a bunch of joins. I have briefly looked into Views on whether I can pull off something like that, but I was unable to quite understand them and I believe they might not be suited. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You're right - views would generate flat data structures so they can't do this. In my opinion, drift's generator should only generate row classes for tables without going into the direction of a full ORM. Resolving references in row classes and queries is not in scope for this project. I think drift is a great platform for others to build this on: Drift builders emit their results as hidden If you don't mind writing the queries yourself, you can use nested results in drift files which would give you a similar structure. |
Beta Was this translation helpful? Give feedback.
You're right - views would generate flat data structures so they can't do this.
In my opinion, drift's generator should only generate row classes for tables without going into the direction of a full ORM. Resolving references in row classes and queries is not in scope for this project. I think drift is a great platform for others to build this on: Drift builders emit their results as hidden
json
files as well which others could pick up to infer relations and the runtime API can be used to build complex queries too. But I don't think this should be part of drift itself.If you don't mind writing the queries yourself, you can use nested results in drift files which would give you a similar …