Open alguintu opened 5 months ago
The jsonb
data type can be done as follows. The @Column
annotation is optional. Just added it for clarity. @serializable
annotation is not designed to work with jsonb object. Check out the test case has_map_test.dart
under angel_orm_test
folder.
@orm
@serializable
abstract class _User extends Model {
String get name;
@Column(type: ColumnType.jsonb)
Map<String, String>? profile = {};
void updateProfile(Profile p) {
profile = p.toMap();
}
Profile retrieveProfile() {
return Profile()..fromMap(profile ?? {});
}
}
class Profile {
String firstName = '';
String lastName = '';
Map<String, String> toMap() {
var result = <String, String>{};
result['firstName'] = firstName;
result['lastName'] = lastName;
return result;
}
void fromMap(Map<String, String> m) {
firstName = m['firstName'] ?? '';
lastName = m['lastName'] ?? '';
}
}
When using a non-orm
serializable
as a column, source_gen triggers a warning that leads to migration fail:Running build_runner succeeds with the following warning:
And then when I try to run
dart bin/migrate.dart up
I get the following error:What am I missing here? The point is to use a serializable class for a jsonb column, but the generator seems to want to be able to query using that jsonb field. Any hints to what I'm doing wrong would be really appreciated. Thanks.