jsonb
This commit is contained in:
parent
554407d159
commit
7040712a14
6 changed files with 76 additions and 5 deletions
|
@ -1,3 +1,6 @@
|
|||
# 2.0.0-dev.3
|
||||
* Add JSON/JSONB support for Maps.
|
||||
|
||||
# 2.0.0-dev.2
|
||||
* Changes to work with `package:angel_orm@2.0.0-dev.15`.
|
||||
|
||||
|
|
|
@ -153,7 +153,11 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
|||
expr = expr.property('toString').call([]);
|
||||
else if (field is RelationFieldImpl)
|
||||
continue;
|
||||
else
|
||||
else if (ctx.columns[field.name]?.type == ColumnType.json) {
|
||||
expr = refer('json')
|
||||
.property('decode')
|
||||
.call([expr.asA(refer('String'))]).asA(type);
|
||||
} else
|
||||
expr = expr.asA(type);
|
||||
|
||||
args[field.name] = expr;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel_orm_generator
|
||||
version: 2.0.0-dev.2
|
||||
version: 2.0.0-dev.3
|
||||
description: Code generators for Angel's ORM. Generates query builder classes.
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/orm
|
||||
|
@ -34,6 +34,6 @@ dev_dependencies:
|
|||
collection: ^1.0.0
|
||||
postgres: ^1.0.0
|
||||
test: ^1.0.0
|
||||
dependency_overrides:
|
||||
angel_orm:
|
||||
path: ../angel_orm
|
||||
# dependency_overrides:
|
||||
# angel_orm:
|
||||
# path: ../angel_orm
|
||||
|
|
57
angel_orm_generator/test/has_map_test.dart
Normal file
57
angel_orm_generator/test/has_map_test.dart
Normal file
|
@ -0,0 +1,57 @@
|
|||
import 'package:test/test.dart';
|
||||
import 'models/has_map.dart';
|
||||
import 'common.dart';
|
||||
|
||||
main() {
|
||||
PostgresExecutor executor;
|
||||
|
||||
setUp(() async {
|
||||
executor = await connectToPostgres(['has_map']);
|
||||
});
|
||||
|
||||
test('insert', () async {
|
||||
var query = HasMapQuery()..values.value = {'foo': 'bar'};
|
||||
var model = await query.insert(executor);
|
||||
print(model.toJson());
|
||||
expect(model, HasMap(value: {'foo': 'bar'}));
|
||||
});
|
||||
|
||||
test('insert', () async {
|
||||
var query = HasMapQuery()..values.value = {'foo': 'bar'};
|
||||
var model = await query.insert(executor);
|
||||
print(model.toJson());
|
||||
|
||||
query = HasMapQuery()..values.copyFrom(model);
|
||||
expect(await query.updateOne(executor), model);
|
||||
});
|
||||
|
||||
group('query', () {
|
||||
HasMap initialValue;
|
||||
|
||||
setUp(() async {
|
||||
var query = HasMapQuery()..values.value = {'foo': 'bar'};
|
||||
initialValue = await query.insert(executor);
|
||||
});
|
||||
|
||||
test('get all', () async {
|
||||
var query = HasMapQuery();
|
||||
expect(await query.get(executor), [initialValue]);
|
||||
});
|
||||
|
||||
test('map equals', () async {
|
||||
var query = HasMapQuery();
|
||||
query.where.value.equals({'foo': 'bar'});
|
||||
expect(await query.get(executor), [initialValue]);
|
||||
});
|
||||
|
||||
test('property equals', () async {
|
||||
var query = HasMapQuery();
|
||||
query.where.value['foo'].asString((b) => b.equals('bar'));
|
||||
expect(await query.get(executor), [initialValue]);
|
||||
|
||||
query = HasMapQuery();
|
||||
query.where.value['foo'].asString((b) => b.equals('baz'));
|
||||
expect(await query.get(executor), []);
|
||||
});
|
||||
});
|
||||
}
|
6
angel_orm_generator/test/migrations/has_map.sql
Normal file
6
angel_orm_generator/test/migrations/has_map.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
CREATE TEMPORARY TABLE "has_maps" (
|
||||
id serial PRIMARY KEY,
|
||||
value jsonb not null,
|
||||
created_at timestamp,
|
||||
updated_at timestamp
|
||||
);
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:convert';
|
||||
import 'package:angel_migration/angel_migration.dart';
|
||||
import 'package:angel_model/angel_model.dart';
|
||||
import 'package:angel_orm/angel_orm.dart';
|
||||
|
|
Loading…
Reference in a new issue