Migrated to NNBD
This commit is contained in:
parent
a32bb29af6
commit
bf9bf67fa8
6 changed files with 84 additions and 84 deletions
|
@ -13,22 +13,22 @@ Future<void> configureServer(Angel app) async {
|
|||
var executor = PostgreSqlExecutor(connection, logger: logger);
|
||||
|
||||
app
|
||||
..container.registerSingleton<QueryExecutor>(executor)
|
||||
..container!.registerSingleton<QueryExecutor>(executor)
|
||||
..shutdownHooks.add((_) => connection.close());
|
||||
}
|
||||
|
||||
Future<PostgreSQLConnection> connectToPostgres(Map configuration) async {
|
||||
var postgresConfig = configuration['postgres'] as Map ?? {};
|
||||
var postgresConfig = configuration['postgres'] as Map? ?? {};
|
||||
var connection = PostgreSQLConnection(
|
||||
postgresConfig['host'] as String ?? 'localhost',
|
||||
postgresConfig['port'] as int ?? 5432,
|
||||
postgresConfig['database_name'] as String ??
|
||||
postgresConfig['host'] as String? ?? 'localhost',
|
||||
postgresConfig['port'] as int? ?? 5432,
|
||||
postgresConfig['database_name'] as String? ??
|
||||
Platform.environment['USER'] ??
|
||||
Platform.environment['USERNAME'],
|
||||
username: postgresConfig['username'] as String,
|
||||
password: postgresConfig['password'] as String,
|
||||
timeZone: postgresConfig['time_zone'] as String ?? 'UTC',
|
||||
timeoutInSeconds: postgresConfig['timeout_in_seconds'] as int ?? 30,
|
||||
useSSL: postgresConfig['use_ssl'] as bool ?? false);
|
||||
Platform.environment['USERNAME']!,
|
||||
username: postgresConfig['username'] as String?,
|
||||
password: postgresConfig['password'] as String?,
|
||||
timeZone: postgresConfig['time_zone'] as String? ?? 'UTC',
|
||||
timeoutInSeconds: postgresConfig['timeout_in_seconds'] as int? ?? 30,
|
||||
useSSL: postgresConfig['use_ssl'] as bool? ?? false);
|
||||
return connection;
|
||||
}
|
||||
|
|
|
@ -2,12 +2,12 @@ import 'package:angel_migration/angel_migration.dart';
|
|||
import 'package:angel_model/angel_model.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
part 'greeting.g.dart';
|
||||
|
||||
@serializable
|
||||
@orm
|
||||
abstract class _Greeting extends Model {
|
||||
@SerializableField(isNullable: false)
|
||||
String get message;
|
||||
String? get message;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ class GreetingMigration extends Migration {
|
|||
@override
|
||||
void up(Schema schema) {
|
||||
schema.create('greetings', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.serial('id').primaryKey();
|
||||
table.varChar('message');
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
|
@ -28,7 +28,7 @@ class GreetingMigration extends Migration {
|
|||
// **************************************************************************
|
||||
|
||||
class GreetingQuery extends Query<Greeting, GreetingQueryWhere> {
|
||||
GreetingQuery({Set<String> trampoline}) {
|
||||
GreetingQuery({Set<String>? trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = GreetingQueryWhere(this);
|
||||
|
@ -37,25 +37,25 @@ class GreetingQuery extends Query<Greeting, GreetingQueryWhere> {
|
|||
@override
|
||||
final GreetingQueryValues values = GreetingQueryValues();
|
||||
|
||||
GreetingQueryWhere _where;
|
||||
GreetingQueryWhere? _where;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
Map<String, String> get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
String get tableName {
|
||||
return 'greetings';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
List<String> get fields {
|
||||
return const ['id', 'message', 'created_at', 'updated_at'];
|
||||
}
|
||||
|
||||
@override
|
||||
GreetingQueryWhere get where {
|
||||
GreetingQueryWhere? get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
|
@ -64,19 +64,19 @@ class GreetingQuery extends Query<Greeting, GreetingQueryWhere> {
|
|||
return GreetingQueryWhere(this);
|
||||
}
|
||||
|
||||
static Greeting parseRow(List row) {
|
||||
static Greeting? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = Greeting(
|
||||
id: row[0].toString(),
|
||||
message: (row[1] as String),
|
||||
createdAt: (row[2] as DateTime),
|
||||
updatedAt: (row[3] as DateTime));
|
||||
message: (row[1] as String?),
|
||||
createdAt: (row[2] as DateTime?),
|
||||
updatedAt: (row[3] as DateTime?));
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Optional<Greeting> deserialize(List row) {
|
||||
return Optional.ofNullable(parseRow(row));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,37 +96,37 @@ class GreetingQueryWhere extends QueryWhere {
|
|||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
List<SqlExpressionBuilder> get expressionBuilders {
|
||||
return [id, message, createdAt, updatedAt];
|
||||
}
|
||||
}
|
||||
|
||||
class GreetingQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
Map<String, String> get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get id {
|
||||
return (values['id'] as String);
|
||||
String? get id {
|
||||
return (values['id'] as String?);
|
||||
}
|
||||
|
||||
set id(String value) => values['id'] = value;
|
||||
String get message {
|
||||
return (values['message'] as String);
|
||||
set id(String? value) => values['id'] = value;
|
||||
String? get message {
|
||||
return (values['message'] as String?);
|
||||
}
|
||||
|
||||
set message(String value) => values['message'] = value;
|
||||
DateTime get createdAt {
|
||||
return (values['created_at'] as DateTime);
|
||||
set message(String? value) => values['message'] = value;
|
||||
DateTime? get createdAt {
|
||||
return (values['created_at'] as DateTime?);
|
||||
}
|
||||
|
||||
set createdAt(DateTime value) => values['created_at'] = value;
|
||||
DateTime get updatedAt {
|
||||
return (values['updated_at'] as DateTime);
|
||||
set createdAt(DateTime? value) => values['created_at'] = value;
|
||||
DateTime? get updatedAt {
|
||||
return (values['updated_at'] as DateTime?);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime value) => values['updated_at'] = value;
|
||||
set updatedAt(DateTime? value) => values['updated_at'] = value;
|
||||
void copyFrom(Greeting model) {
|
||||
message = model.message;
|
||||
createdAt = model.createdAt;
|
||||
|
@ -140,22 +140,22 @@ class GreetingQueryValues extends MapQueryValues {
|
|||
|
||||
@generatedSerializable
|
||||
class Greeting extends _Greeting {
|
||||
Greeting({this.id, @required this.message, this.createdAt, this.updatedAt});
|
||||
Greeting({this.id, required this.message, this.createdAt, this.updatedAt});
|
||||
|
||||
@override
|
||||
final String id;
|
||||
final String? id;
|
||||
|
||||
@override
|
||||
final String message;
|
||||
final String? message;
|
||||
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
final DateTime? createdAt;
|
||||
|
||||
@override
|
||||
final DateTime updatedAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
Greeting copyWith(
|
||||
{String id, String message, DateTime createdAt, DateTime updatedAt}) {
|
||||
{String? id, String? message, DateTime? createdAt, DateTime? updatedAt}) {
|
||||
return Greeting(
|
||||
id: id ?? this.id,
|
||||
message: message ?? this.message,
|
||||
|
@ -163,6 +163,7 @@ class Greeting extends _Greeting {
|
|||
updatedAt: updatedAt ?? this.updatedAt);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
return other is _Greeting &&
|
||||
other.id == id &&
|
||||
|
@ -178,7 +179,7 @@ class Greeting extends _Greeting {
|
|||
|
||||
@override
|
||||
String toString() {
|
||||
return "Greeting(id=$id, message=$message, createdAt=$createdAt, updatedAt=$updatedAt)";
|
||||
return 'Greeting(id=$id, message=$message, createdAt=$createdAt, updatedAt=$updatedAt)';
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
|
@ -210,33 +211,31 @@ class GreetingSerializer extends Codec<Greeting, Map> {
|
|||
const GreetingSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const GreetingEncoder();
|
||||
GreetingEncoder get encoder => const GreetingEncoder();
|
||||
|
||||
@override
|
||||
get decoder => const GreetingDecoder();
|
||||
GreetingDecoder get decoder => const GreetingDecoder();
|
||||
static Greeting fromMap(Map map) {
|
||||
if (map['message'] == null) {
|
||||
throw FormatException("Missing required field 'message' on Greeting.");
|
||||
}
|
||||
|
||||
return Greeting(
|
||||
id: map['id'] as String,
|
||||
message: map['message'] as String,
|
||||
id: map['id'] as String?,
|
||||
message: map['message'] as String?,
|
||||
createdAt: map['created_at'] != null
|
||||
? (map['created_at'] is DateTime
|
||||
? (map['created_at'] as DateTime)
|
||||
? (map['created_at'] as DateTime?)
|
||||
: DateTime.parse(map['created_at'].toString()))
|
||||
: null,
|
||||
updatedAt: map['updated_at'] != null
|
||||
? (map['updated_at'] is DateTime
|
||||
? (map['updated_at'] as DateTime)
|
||||
? (map['updated_at'] as DateTime?)
|
||||
: DateTime.parse(map['updated_at'].toString()))
|
||||
: null);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Greeting model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
if (model.message == null) {
|
||||
throw FormatException("Missing required field 'message' on Greeting.");
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
|
|||
app.get('/', (req, res) => res.render('hello'));
|
||||
|
||||
app.get('/greetings', (req, res) {
|
||||
var executor = req.container.make<QueryExecutor>();
|
||||
var executor = req.container!.make<QueryExecutor>()!;
|
||||
var query = GreetingQuery();
|
||||
return query.get(executor);
|
||||
});
|
||||
|
@ -33,7 +33,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
|
|||
if (!req.bodyAsMap.containsKey('message')) {
|
||||
throw AngelHttpException.badRequest(message: 'Missing "message".');
|
||||
} else {
|
||||
var executor = req.container.make<QueryExecutor>();
|
||||
var executor = req.container!.make<QueryExecutor>()!;
|
||||
var message = req.bodyAsMap['message'].toString();
|
||||
var query = GreetingQuery()..values.message = message;
|
||||
return await query.insert(executor);
|
||||
|
@ -42,8 +42,8 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
|
|||
|
||||
app.get('/greetings/:message', (req, res) {
|
||||
var message = req.params['message'] as String;
|
||||
var executor = req.container.make<QueryExecutor>();
|
||||
var query = GreetingQuery()..where.message.equals(message);
|
||||
var executor = req.container!.make<QueryExecutor>()!;
|
||||
var query = GreetingQuery()..where!.message.equals(message);
|
||||
return query.get(executor);
|
||||
});
|
||||
|
||||
|
|
45
pubspec.yaml
45
pubspec.yaml
|
@ -2,94 +2,95 @@ name: angel
|
|||
description: An app that's going to be amazing pretty soon.
|
||||
publish_to: none # Ensure we don't accidentally publish our private code! ;)
|
||||
environment:
|
||||
sdk: '>=2.10.0 <3.0.0'
|
||||
homepage: https://github.com/angel-dart/angel
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
homepage: https://github.com/dukefirehawk/angel
|
||||
dependencies:
|
||||
angel_auth:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/auth
|
||||
angel_configuration:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/configuration
|
||||
angel_framework:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/framework
|
||||
angel_jael:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/jael/angel_jael
|
||||
angel_migration:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/orm/angel_migration
|
||||
angel_orm:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/orm/angel_orm
|
||||
angel_orm_postgres:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/orm/angel_orm_postgres
|
||||
angel_serialize:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/serialize/angel_serialize
|
||||
angel_production:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/production
|
||||
angel_static:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/static
|
||||
angel_validate:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/validate
|
||||
optional: ^6.0.0-nullsafety.2
|
||||
dev_dependencies:
|
||||
angel_hot:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/hot
|
||||
angel_migration_runner:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/orm/angel_migration_runner
|
||||
angel_orm_generator:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/orm/angel_orm_generator
|
||||
angel_serialize_generator:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/serialize/angel_serialize_generator
|
||||
angel_test:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/test
|
||||
build_runner: ^1.11.5 # Runs builds
|
||||
io: ^0.3.0 # For pretty printing.
|
||||
pedantic: ^1.0.0 # Enforces Dart style conventions.
|
||||
test: ^1.0.0 # For unit testing.
|
||||
build_runner: ^2.0.3 # Runs builds
|
||||
io: ^1.0.0 # For pretty printing.
|
||||
pedantic: ^1.11.0 # Enforces Dart style conventions.
|
||||
test: ^1.17.4 # For unit testing.
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import 'package:test/test.dart';
|
|||
// https://github.com/dart-lang/test
|
||||
|
||||
void main() async {
|
||||
TestClient client;
|
||||
late TestClient client;
|
||||
|
||||
setUp(() async {
|
||||
var app = Angel();
|
||||
|
@ -35,7 +35,7 @@ void main() async {
|
|||
|
||||
test('index returns 200', () async {
|
||||
// Request a resource at the given path.
|
||||
var response = await client.get('/');
|
||||
var response = await client.get(Uri.parse('/'));
|
||||
|
||||
// Expect a 200 response.
|
||||
expect(response, hasStatus(200));
|
||||
|
|
Loading…
Reference in a new issue