Update orm_mysql

This commit is contained in:
thomashii 2021-06-18 18:17:13 +08:00
parent 286ad100f0
commit 4141c60c50
18 changed files with 131 additions and 137 deletions

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/packages" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/test/packages" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/angel_mongo.iml" filepath="$PROJECT_DIR$/.idea/angel_mongo.iml" />
</modules>
</component>
</project>

View file

@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="All Tests" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true">
<option name="filePath" value="$PROJECT_DIR$/test" />
<option name="scope" value="FOLDER" />
<method />
</configuration>
</component>

View file

@ -1,6 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Generic Tests" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true">
<option name="filePath" value="$PROJECT_DIR$/test/generic_test.dart" />
<method />
</configuration>
</component>

View file

@ -1,6 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Typed Tests" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true">
<option name="filePath" value="$PROJECT_DIR$/test/typed_test.dart" />
<method />
</configuration>
</component>

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View file

@ -1,3 +1,6 @@
# 3.0.0
* Migrated to support Dart SDK 2.12.x NNBD
# 2.0.3
* Add null-coalescing check when processing queries: https://github.com/angel-dart/mongo/pull/12

View file

@ -1,6 +1,6 @@
MIT License (MIT)
The MIT License (MIT)
Copyright (c) 2021 dukefirehawk.com
Copyright (c) 2016 angel-dart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.

View file

@ -2,14 +2,14 @@ import 'package:angel_framework/angel_framework.dart';
import 'package:angel_mongo/angel_mongo.dart';
import 'package:mongo_dart/mongo_dart.dart';
main() async {
var app = new Angel();
Db db = new Db('mongodb://localhost:27017/local');
void main() async {
var app = Angel();
var db = Db('mongodb://localhost:27017/local');
await db.open();
var service = app.use('/api/users', new MongoService(db.collection("users")));
var service = app.use('/api/users', MongoService(db.collection('users')));
service.afterCreated.listen((event) {
print("New user: ${event.result}");
print('New user: ${event.result}');
});
}

View file

@ -89,7 +89,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
@override
Future<List<Map<String, dynamic>>> index(
[Map<String, dynamic> params]) async {
return await (await collection.find(_makeQuery(params)))
return await (collection.find(_makeQuery(params)))
.map((x) => _jsonify(x, params))
.toList();
}
@ -110,7 +110,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
upsert: true);
return _jsonify(result);
} catch (e, st) {
throw new AngelHttpException(e, stackTrace: st);
throw AngelHttpException(e, stackTrace: st);
}
}
@ -122,7 +122,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
var found = await collection.findOne(_makeQuery(params));
if (found == null) {
throw new AngelHttpException.notFound(message: errorMessage);
throw AngelHttpException.notFound(message: errorMessage);
}
return _jsonify(found, params);
@ -131,11 +131,11 @@ class MongoService extends Service<String, Map<String, dynamic>> {
@override
Future<Map<String, dynamic>> read(String id,
[Map<String, dynamic> params]) async {
ObjectId _id = _makeId(id);
var _id = _makeId(id);
var found = await collection.findOne(where.id(_id).and(_makeQuery(params)));
if (found == null) {
throw new AngelHttpException.notFound(
throw AngelHttpException.notFound(
message: 'No record found for ID ${_id.toHexString()}');
}
@ -147,9 +147,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
[Map<String, dynamic> params]) async {
var q = _makeQuery(params);
q = ids.fold(q, (q, id) => q.or(where.id(_makeId(id))));
return await (await collection.find(q))
.map((x) => _jsonify(x, params))
.toList();
return await (collection.find(q)).map((x) => _jsonify(x, params)).toList();
}
@override
@ -160,10 +158,11 @@ class MongoService extends Service<String, Map<String, dynamic>> {
try {
target = await read(id, params);
} on AngelHttpException catch (e) {
if (e.statusCode == 404)
if (e.statusCode == 404) {
return await create(data, params);
else
} else {
rethrow;
}
}
var result = mergeMap([target, _removeSensitive(data)]);
@ -177,7 +176,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
return result;
} catch (e, st) {
//printDebug(e, st, 'MODIFY');
throw new AngelHttpException(e, stackTrace: st);
throw AngelHttpException(e, stackTrace: st);
}
}
@ -205,7 +204,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
return result;
} catch (e, st) {
//printDebug(e, st, 'UPDATE');
throw new AngelHttpException(e, stackTrace: st);
throw AngelHttpException(e, stackTrace: st);
}
}
@ -232,7 +231,7 @@ class MongoService extends Service<String, Map<String, dynamic>> {
return _jsonify(result);
} catch (e, st) {
//printDebug(e, st, 'REMOVE');
throw new AngelHttpException(e, stackTrace: st);
throw AngelHttpException(e, stackTrace: st);
}
}
}

View file

@ -1,17 +1,28 @@
name: angel_mongo
version: 2.0.3
version: 3.0.0
description: MongoDB-enabled services for the Angel framework. Well-tested.
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_mongo
publish_to: none
environment:
sdk: '>=2.10.0 <2.12.0'
sdk: '>=2.10.0 <3.0.0'
dependencies:
angel_framework: #^2.0.0-alpha
path: ../framework
json_god: ">=2.0.0-beta <3.0.0"
merge_map: ^1.0.0
mongo_dart: ^0.4.4
angel_framework:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/framework
json_god:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/json_god
merge_map:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/merge_map
mongo_dart: ^0.7.0
dev_dependencies:
http: ^0.12.2
http: ^0.13.0
pedantic: ^1.0.0
test: ^1.15.7

View file

@ -15,7 +15,7 @@ final Map testGreeting = {'to': 'world'};
void wireHooked(HookedService hooked) {
hooked.afterAll((HookedServiceEvent event) {
print("Just ${event.eventName}: ${event.result}");
print('Just ${event.eventName}: ${event.result}');
print('Params: ${event.params}');
});
}
@ -74,11 +74,11 @@ void main() {
});
test('insert items', () async {
var response = await client.post("$url/api",
var response = await client.post(Uri.parse('$url/api'),
body: god.serialize(testGreeting), headers: headers);
expect(response.statusCode, isIn([200, 201]));
response = await client.get("$url/api");
response = await client.get(Uri.parse('$url/api'));
expect(response.statusCode, isIn([200, 201]));
var users = god.deserialize(response.body,
outputType: <Map>[].runtimeType) as List<Map>;
@ -86,12 +86,12 @@ void main() {
});
test('read item', () async {
var response = await client.post("$url/api",
var response = await client.post(Uri.parse('$url/api'),
body: god.serialize(testGreeting), headers: headers);
expect(response.statusCode, isIn([200, 201]));
var created = god.deserialize(response.body) as Map;
response = await client.get("$url/api/${created['id']}");
response = await client.get(Uri.parse("$url/api/${created['id']}"));
expect(response.statusCode, isIn([200, 201]));
var read = god.deserialize(response.body) as Map;
expect(read['id'], equals(created['id']));
@ -100,7 +100,7 @@ void main() {
});
test('findOne', () async {
var response = await client.post("$url/api",
var response = await client.post(Uri.parse('$url/api'),
body: god.serialize(testGreeting), headers: headers);
expect(response.statusCode, isIn([200, 201]));
var created = god.deserialize(response.body) as Map;
@ -113,7 +113,7 @@ void main() {
});
test('readMany', () async {
var response = await client.post("$url/api",
var response = await client.post(Uri.parse('$url/api'),
body: god.serialize(testGreeting), headers: headers);
expect(response.statusCode, isIn([200, 201]));
var created = god.deserialize(response.body) as Map;
@ -125,13 +125,13 @@ void main() {
});
test('modify item', () async {
var response = await client.post("$url/api",
var response = await client.post(Uri.parse('$url/api'),
body: god.serialize(testGreeting), headers: headers);
expect(response.statusCode, isIn([200, 201]));
var created = god.deserialize(response.body) as Map;
response = await client.patch("$url/api/${created['id']}",
body: god.serialize({"to": "Mom"}), headers: headers);
response = await client.patch(Uri.parse("$url/api/${created['id']}"),
body: god.serialize({'to': 'Mom'}), headers: headers);
var modified = god.deserialize(response.body) as Map;
expect(response.statusCode, isIn([200, 201]));
expect(modified['id'], equals(created['id']));
@ -140,13 +140,13 @@ void main() {
});
test('update item', () async {
var response = await client.post("$url/api",
var response = await client.post(Uri.parse('$url/api'),
body: god.serialize(testGreeting), headers: headers);
expect(response.statusCode, isIn([200, 201]));
var created = god.deserialize(response.body) as Map;
response = await client.post("$url/api/${created['id']}",
body: god.serialize({"to": "Updated"}), headers: headers);
response = await client.post(Uri.parse("$url/api/${created['id']}"),
body: god.serialize({'to': 'Updated'}), headers: headers);
var modified = god.deserialize(response.body) as Map;
expect(response.statusCode, isIn([200, 201]));
expect(modified['id'], equals(created['id']));
@ -155,38 +155,38 @@ void main() {
});
test('remove item', () async {
var response = await client.post("$url/api",
var response = await client.post(Uri.parse('$url/api'),
body: god.serialize(testGreeting), headers: headers);
var created = god.deserialize(response.body) as Map;
int lastCount = (await greetingService.index()).length;
var lastCount = (await greetingService.index()).length;
await client.delete("$url/api/${created['id']}");
await client.delete(Uri.parse("$url/api/${created['id']}"));
expect((await greetingService.index()).length, equals(lastCount - 1));
});
test('cannot remove all unless explicitly set', () async {
var response = await client.delete('$url/api/null');
var response = await client.delete(Uri.parse('$url/api/null'));
expect(response.statusCode, 403);
});
test('\$sort and query parameters', () async {
// Search by where.eq
Map world = await greetingService.create({"to": "world"});
await greetingService.create({"to": "Mom"});
await greetingService.create({"to": "Updated"});
Map world = await greetingService.create({'to': 'world'});
await greetingService.create({'to': 'Mom'});
await greetingService.create({'to': 'Updated'});
var response = await client.get("$url/api?to=world");
var response = await client.get(Uri.parse('$url/api?to=world'));
print(response.body);
var queried = god.deserialize(response.body,
outputType: <Map>[].runtimeType) as List<Map>;
expect(queried.length, equals(1));
expect(queried[0].keys.length, equals(2));
expect(queried[0]["id"], equals(world["id"]));
expect(queried[0]["to"], equals(world["to"]));
expect(queried[0]['id'], equals(world['id']));
expect(queried[0]['to'], equals(world['to']));
//expect(queried[0]["createdAt"], equals(world["createdAt"]));
/*response = await client.get("$url/api?\$sort.createdAt=-1");
/*response = await client.get(Uri.parse("$url/api?\$sort.createdAt=-1"));
print(response.body);
queried = god.deserialize(response.body);
expect(queried[0]["id"], equals(Updated["id"]));
@ -194,8 +194,8 @@ void main() {
expect(queried[2]["id"], equals(world["id"]));*/
queried = await greetingService.index({
"\$query": {
"_id": where.id(ObjectId.fromHexString(world["id"] as String))
'\$query': {
'_id': where.id(ObjectId.fromHexString(world['id'] as String))
}
});
print(queried);

21
packages/orm/LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License (MIT)
Copyright (c) 2021 dukefirehawk.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,13 +1,14 @@
# orm
[![Pub](https://img.shields.io/pub/v/angel_orm.svg)](https://pub.dartlang.org/packages/angel_orm)
[![build status](https://travis-ci.org/angel-dart/orm.svg)](https://travis-ci.org/angel-dart/orm)
# ORM
[![version](https://img.shields.io/badge/pub-v4.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_orm)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
Source-generated PostgreSQL ORM for use with the
[Angel framework](https://angel-dart.github.io).
Now you can combine the power and flexibility of Angel with a strongly-typed ORM.
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/LICENSE)
Source-generated ORM for use with the [Angel3 framework](https://github.com/dukefirehawk/angel). Now you can combine the power and flexibility of Angel3 with a strongly-typed ORM.
Documentation for migrations can be found here:
https://angel-dart.gitbook.io/angel/v/2.x/orm/migrations
[ORM Migration](https://angel3-docs.dukefirehawk.com/guides/orm/migrations)
* [Usage](#usage)
* [Model Definitions](#models)
@ -23,29 +24,28 @@ https://angel-dart.gitbook.io/angel/v/2.x/orm/migrations
You'll need these dependencies in your `pubspec.yaml`:
```yaml
dependencies:
angel_orm: ^2.0.0-dev
angel3_orm: ^4.0.0-beta.1
dev_dependencies:
angel_orm_generator: ^2.0.0-dev
build_runner: ^1.0.0
angel3_orm_generator: ^4.0.0-beta.1
build_runner: ^2.0.0
```
`package:angel_orm_generator` exports a class that you can include
in a `package:build` flow:
`package:angel3_orm_generator` exports a class that you can include in a `package:build` flow:
* `PostgresOrmGenerator` - Fueled by `package:source_gen`; include this within a `SharedPartBuilder`.
However, it also includes a `build.yaml` that builds ORM files automatically, so you shouldn't
have to do any configuration at all.
# Models
The ORM works best when used with `package:angel_serialize`:
The ORM works best when used with `package:angel3_serialize`:
```dart
library angel_orm.test.models.car;
import 'package:angel_migration/angel_migration.dart';
import 'package:angel_model/angel_model.dart';
import 'package:angel_orm/angel_orm.dart';
import 'package:angel_serialize/angel_serialize.dart';
import 'package:angel3_migration/angel3_migration.dart';
import 'package:angel3_model/angel3_model.dart';
import 'package:angel3_orm/angel3_orm.dart';
import 'package:angel3_serialize/angel3_serialize.dart';
part 'car.g.dart';
@serializable
@ -65,7 +65,7 @@ abstract class _Car extends Model {
abstract class _NoMigrations extends Model {}
```
Models can use the `@SerializableField()` annotation; `package:angel_orm` obeys it.
Models can use the `@SerializableField()` annotation; `package:angel3_orm` obeys it.
After building, you'll have access to a `Query` class with strongly-typed methods that
allow to run asynchronous queries without a headache.
@ -86,8 +86,8 @@ abstract class _ThisIsNotAnAngelModel {
MVC just got a whole lot easier:
```dart
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_orm/angel_orm.dart';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_orm/angel3_orm.dart';
import 'car.dart';
import 'car.orm.g.dart';
@ -110,7 +110,7 @@ class CarController extends Controller {
@Expose('/recalled_since_2008')
carsRecalledSince2008(QueryExecutor executor) {
// Instantiate a Car query, which is auto-generated. This class helps us build fluent queries easily.
var query = new CarQuery();
var query = CarQuery();
query.where
..familyFriendly.equals(false)
..recalledAt.year.greaterThanOrEqualTo(2008);
@ -128,7 +128,7 @@ class CarController extends Controller {
createCar(QueryExecutor executor) async {
// `package:angel_orm` generates a strongly-typed `insert` function on the query class.
// Say goodbye to typos!!!
var query = new CarQuery();
var query = CarQuery();
query.values
..familyFriendly = true
..make 'Honda';
@ -141,7 +141,7 @@ class CarController extends Controller {
```
# Relations
`angel_orm` supports the following relationships:
`angel3_orm` supports the following relationships:
* `@HasOne()` (one-to-one)
* `@HasMany()` (one-to-many)

View file

@ -1,2 +1,12 @@
Tobe O <thosakwe@gmail.com>
Thomas Hii <thomashii@dukefirehawk.com>
Primary Authors
===============
* __[Thomas Hii](dukefirehawk.apps@gmail.com)__
Thomas is the current maintainer of the code base. He has refactored and migrated the
code base to support NNBD.
* __[Tobe O](thosakwe@gmail.com)__
Tobe has written much of the original code prior to NNBD migration. He has moved on and
is no longer involved with the project.

View file

@ -1,8 +1,5 @@
# 3.0.0
# 2.0.0-beta.1
* Migrated to support Dart SDK 2.12.x NNBD
# 2.0.0
* Migrated to work with Dart SDK 2.12.x Non NNBD
# 1.0.0
* First version.

View file

@ -1,5 +1,5 @@
# angel3_orm_mysql
[![version](https://img.shields.io/badge/pub-v4.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_orm_mysql)
[![version](https://img.shields.io/badge/pub-v2.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_orm_mysql)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)

View file

@ -0,0 +1,4 @@
include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false