Compare commits
27 commits
angel3-orm
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
d6a81afab5 | ||
|
fd4abfaf43 | ||
|
d171e49fc2 | ||
|
debada01f2 | ||
|
4bdddcdfed | ||
|
023d239c1f | ||
|
6867696218 | ||
|
f46ec8058d | ||
|
597ea5323a | ||
|
8a6bd74bf2 | ||
|
2f8dd31c6a | ||
|
dfd864f0b7 | ||
|
9e66a1af47 | ||
|
be518fa3c0 | ||
|
197e4c95e5 | ||
|
89dde22a52 | ||
|
539696222d | ||
|
c19f92ba35 | ||
|
d74bde03e2 | ||
|
e986fca7bb | ||
|
41d83a274b | ||
|
528dca2db9 | ||
|
93cdb671d5 | ||
|
ff8b0e60a8 | ||
|
00b14878a8 | ||
|
4f1913d517 | ||
|
a8dc7ef515 |
24 changed files with 85 additions and 548 deletions
|
@ -1,11 +1,10 @@
|
||||||
.dart_tool
|
.dart_tool
|
||||||
.idea
|
.idea
|
||||||
|
.pub
|
||||||
.vscode
|
.vscode
|
||||||
.metals
|
|
||||||
.git
|
|
||||||
.github
|
|
||||||
.packages
|
|
||||||
logs/
|
logs/
|
||||||
test/
|
test/
|
||||||
build/
|
build/
|
||||||
pubspec.lock
|
.analysis-options
|
||||||
|
.packages
|
||||||
|
*.g.dart
|
3
.github/FUNDING.yml
vendored
Normal file
3
.github/FUNDING.yml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: [thosakwe]
|
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -11,6 +11,7 @@
|
||||||
.project
|
.project
|
||||||
.pub/
|
.pub/
|
||||||
.scripts-bin/
|
.scripts-bin/
|
||||||
|
.metals/
|
||||||
build/
|
build/
|
||||||
**/packages/
|
**/packages/
|
||||||
|
|
||||||
|
@ -57,6 +58,8 @@ pubspec.lock
|
||||||
# Mongo Explorer plugin:
|
# Mongo Explorer plugin:
|
||||||
.idea/mongoSettings.xml
|
.idea/mongoSettings.xml
|
||||||
|
|
||||||
|
.vscode/
|
||||||
|
|
||||||
## File-based project format:
|
## File-based project format:
|
||||||
*.iws
|
*.iws
|
||||||
|
|
||||||
|
@ -78,7 +81,7 @@ crashlytics-build.properties
|
||||||
fabric.properties
|
fabric.properties
|
||||||
|
|
||||||
### VSCode template
|
### VSCode template
|
||||||
.vscode/
|
.vscode/*
|
||||||
!.vscode/settings.json
|
!.vscode/settings.json
|
||||||
!.vscode/tasks.json
|
!.vscode/tasks.json
|
||||||
!.vscode/launch.json
|
!.vscode/launch.json
|
||||||
|
@ -88,5 +91,3 @@ logs/
|
||||||
*.pem
|
*.pem
|
||||||
.DS_Store
|
.DS_Store
|
||||||
server_log.txt
|
server_log.txt
|
||||||
|
|
||||||
.metals/
|
|
||||||
|
|
12
AUTHORS.md
Normal file
12
AUTHORS.md
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
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.
|
|
@ -2,4 +2,6 @@
|
||||||
|
|
||||||
## 1.0.0
|
## 1.0.0
|
||||||
|
|
||||||
* Initial version
|
* Changed to use `angel3` packages
|
||||||
|
* Updated to support NNBD
|
||||||
|
* Updated linter to `package:lints`
|
||||||
|
|
25
CONTRIBUTING.md
Normal file
25
CONTRIBUTING.md
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
# Contribution
|
||||||
|
|
||||||
|
Any help from the open-source community is always welcome and needed:
|
||||||
|
|
||||||
|
1. Found an issue?
|
||||||
|
- Please [fill a bug report][tracker] with error message and steps to reproduce it.
|
||||||
|
2. Wish a feature?
|
||||||
|
- Open a feature request with use cases.
|
||||||
|
3. Are you using and liking the project?
|
||||||
|
- Create an article about your use case
|
||||||
|
- Do a post on your likes and dislikes
|
||||||
|
- Make a donation.
|
||||||
|
4. Are you a developer?
|
||||||
|
- Fix a bug and send a [pull request][pull_request]
|
||||||
|
- Implement a new feature
|
||||||
|
- Improve the Unit Tests
|
||||||
|
- Improve the [User Guide][doc] and send a [document pull request][doc_repo]
|
||||||
|
5. Have you already helped in any way?
|
||||||
|
- **Many thanks to the contributors and everybody that uses this project!**
|
||||||
|
|
||||||
|
[tracker]: https://github.com/dukefirehawk/angel/issues
|
||||||
|
[pull_request]: https://github.com/dukefirehawk/angel/pulls
|
||||||
|
[doc]: https://angel3-docs.dukefirehawk.com
|
||||||
|
[doc_repo]: https://github.com/dukefirehawk/angel3-guide/pulls
|
|
@ -20,5 +20,4 @@ EXPOSE 3000
|
||||||
CMD dart ./bin/prod.dart -p 3000 -a 0.0.0.0
|
CMD dart ./bin/prod.dart -p 3000 -a 0.0.0.0
|
||||||
|
|
||||||
# Use -j flag to set higher number of isolates
|
# Use -j flag to set higher number of isolates
|
||||||
#CMD dart ./bin/prod.dart -p 3000 -a 0.0.0.0 -j 50
|
#CMD dart ./bin/prod.dart -p 3000 -a 0.0.0.0 -j 50
|
||||||
|
|
58
README.md
58
README.md
|
@ -1,35 +1,11 @@
|
||||||
# ORM Starter Application for Angel3 framework
|
|
||||||
|
|
||||||
This is an ORM starter application for [Angel3 framework](https://angel3-framework.web.app) which is a full-stack Web framework in Dart. The default database is MariaDB. MySQL support is still in active development.
|
# Basic Starter Application for Angel3 framework
|
||||||
|
|
||||||
|
This is a basic starter application for [Angel3 framework](https://angel3-framework.web.app) which is a full-stack Web framework in Dart.
|
||||||
|
|
||||||
## Installation & Setup
|
## Installation & Setup
|
||||||
|
|
||||||
1. Download and install [Dart](https://dart.dev/get-dart).
|
1. Download and install [Dart](https://dart.dev/get-dart).
|
||||||
2. Install `MariaDB` 10.2.x or later
|
|
||||||
3. Create a new user and database using MySQL Client. For example:
|
|
||||||
|
|
||||||
```sql
|
|
||||||
MariaDB [(none)]> CREATE DATABASE appdb;
|
|
||||||
MariaDB [(none)]> CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'App1970#';
|
|
||||||
MariaDB [(none)]> GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
|
|
||||||
```
|
|
||||||
|
|
||||||
4. Update the `mariadb` section in the `config/default.yaml` file with the newly created user and database name.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
mariadb:
|
|
||||||
host: localhost
|
|
||||||
port: 3306
|
|
||||||
database_name: appdb
|
|
||||||
username: appuser
|
|
||||||
password: App1970#
|
|
||||||
```
|
|
||||||
|
|
||||||
5. Run the migration to generate `migrations` and `greetings` tables in the database.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
dart bin/migrate.dart up
|
|
||||||
```
|
|
||||||
|
|
||||||
### Development
|
### Development
|
||||||
|
|
||||||
|
@ -41,24 +17,6 @@ This is an ORM starter application for [Angel3 framework](https://angel3-framewo
|
||||||
|
|
||||||
2. Modify the code and watch the changes applied to the application
|
2. Modify the code and watch the changes applied to the application
|
||||||
|
|
||||||
3. Insert a message into DB:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -H "Content-Type: application/json" -X POST -d '{"message":"OK_Message" }' "http://localhost:3000/greetings/"
|
|
||||||
```
|
|
||||||
|
|
||||||
or
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -X POST -d 'message=OK_Message2' "http://localhost:3000/greetings/"
|
|
||||||
```
|
|
||||||
|
|
||||||
4. Query DB:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl http://localhost:3000/greetings/
|
|
||||||
```
|
|
||||||
|
|
||||||
### Production
|
### Production
|
||||||
|
|
||||||
1. Run the following command:
|
1. Run the following command:
|
||||||
|
@ -69,18 +27,8 @@ This is an ORM starter application for [Angel3 framework](https://angel3-framewo
|
||||||
|
|
||||||
2. Run as docker. Edit and run the provided `Dockerfile` to build the image.
|
2. Run as docker. Edit and run the provided `Dockerfile` to build the image.
|
||||||
|
|
||||||
### Building ORM Model
|
|
||||||
|
|
||||||
1. Run the followig command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
dart run build_runner build
|
|
||||||
```
|
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
|
|
||||||
Visit the [Developer Guide](https://angel3-docs.dukefirehawk.com/guides) for dozens of guides and resources, including video tutorials, to get up and running as quickly as possible with Angel3.
|
Visit the [Developer Guide](https://angel3-docs.dukefirehawk.com/guides) for dozens of guides and resources, including video tutorials, to get up and running as quickly as possible with Angel3.
|
||||||
|
|
||||||
Examples and complete projects can be found [here](https://angel3-framework.web.app/#/examples).
|
Examples and complete projects can be found [here](https://angel3-framework.web.app/#/examples).
|
||||||
|
|
||||||
You can also view the [API Documentation](https://pub.dev/documentation/angel3_framework/latest/).
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
include: package:lints/recommended.yaml
|
include: package:lints/recommended.yaml
|
|
@ -1,10 +1,10 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:angel/angel.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:belatuk_pretty_logging/belatuk_pretty_logging.dart';
|
import 'package:belatuk_pretty_logging/belatuk_pretty_logging.dart';
|
||||||
import 'package:angel3_container/mirrors.dart';
|
import 'package:angel3_container/mirrors.dart';
|
||||||
import 'package:angel3_framework/angel3_framework.dart';
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_hot/angel3_hot.dart';
|
import 'package:angel3_hot/angel3_hot.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:angel/angel.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
// Watch the config/ and web/ directories for changes, and hot-reload the server.
|
// Watch the config/ and web/ directories for changes, and hot-reload the server.
|
||||||
|
@ -24,5 +24,5 @@ void main() async {
|
||||||
|
|
||||||
var server = await hot.startServer('127.0.0.1', 3000);
|
var server = await hot.startServer('127.0.0.1', 3000);
|
||||||
print(
|
print(
|
||||||
'[angel] server listening at http://${server.address.address}:${server.port}');
|
'[Angel3] server listening at http://${server.address.address}:${server.port}');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
import 'package:angel/src/config/plugins/orm.dart';
|
|
||||||
import 'package:angel/models.dart';
|
|
||||||
import 'package:angel3_configuration/angel3_configuration.dart';
|
|
||||||
import 'package:angel3_migration_runner/angel3_migration_runner.dart';
|
|
||||||
import 'package:angel3_migration_runner/mariadb.dart';
|
|
||||||
//import 'package:angel3_migration_runner/mysql.dart';
|
|
||||||
import 'package:file/local.dart';
|
|
||||||
import 'package:logging/logging.dart';
|
|
||||||
|
|
||||||
void main(List<String> args) async {
|
|
||||||
// Enable the logging
|
|
||||||
Logger.root.level = Level.INFO;
|
|
||||||
Logger.root.onRecord.listen((rec) {
|
|
||||||
print('${rec.time}: ${rec.level.name}: ${rec.loggerName}: ${rec.message}');
|
|
||||||
|
|
||||||
if (rec.error != null) {
|
|
||||||
print(rec.error);
|
|
||||||
print(rec.stackTrace);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var fs = LocalFileSystem();
|
|
||||||
var configuration = await loadStandaloneConfiguration(fs);
|
|
||||||
|
|
||||||
// MariaDB database
|
|
||||||
var connection = await connectToMariaDb(configuration);
|
|
||||||
var migrationRunner = MariaDbMigrationRunner(connection, migrations: [
|
|
||||||
GreetingMigration(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// MySQL database
|
|
||||||
/*
|
|
||||||
var connection = await connectToMysql(configuration);
|
|
||||||
var migrationRunner = MySqlMigrationRunner(connection, migrations: [
|
|
||||||
GreetingMigration(),
|
|
||||||
]);
|
|
||||||
*/
|
|
||||||
|
|
||||||
await runMigrations(migrationRunner, args);
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
import 'package:angel/angel.dart';
|
|
||||||
import 'package:angel3_container/mirrors.dart';
|
import 'package:angel3_container/mirrors.dart';
|
||||||
import 'package:angel3_production/angel3_production.dart';
|
import 'package:angel3_production/angel3_production.dart';
|
||||||
|
import 'package:angel/angel.dart';
|
||||||
|
|
||||||
// NOTE: By default, the Runner class does not use the `MirrorsReflector`, or any
|
// NOTE: By default, the Runner class does not use the `MirrorsReflector`, or any
|
||||||
// reflector, by default.
|
// reflector, by default.
|
||||||
|
|
|
@ -1,14 +1,5 @@
|
||||||
# Default server configuration.
|
# Default server configuration.
|
||||||
jwt_secret: INSECURE_DEFAULT_SECRET
|
jwt_secret: INSECURE_DEFAULT_SECRET
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
|
mongo_db: mongodb://localhost:27017/angel
|
||||||
port: 3000
|
port: 3000
|
||||||
mysql:
|
|
||||||
host: localhost
|
|
||||||
port: 3306
|
|
||||||
database_name: appdb
|
|
||||||
username: appuser
|
|
||||||
password: App1970#
|
|
||||||
use_ssl: false
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
export 'src/models/greeting.dart';
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/// Configuration for this Angel instance.
|
||||||
import 'package:angel3_configuration/angel3_configuration.dart';
|
import 'package:angel3_configuration/angel3_configuration.dart';
|
||||||
import 'package:angel3_framework/angel3_framework.dart';
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_jael/angel3_jael.dart';
|
import 'package:angel3_jael/angel3_jael.dart';
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
import 'dart:async';
|
|
||||||
import 'dart:io';
|
|
||||||
import 'package:angel3_framework/angel3_framework.dart';
|
|
||||||
import 'package:angel3_orm/angel3_orm.dart';
|
|
||||||
import 'package:angel3_orm_mysql/angel3_orm_mysql.dart';
|
|
||||||
import 'package:mysql1/mysql1.dart';
|
|
||||||
//import 'package:mysql_client/mysql_client.dart';
|
|
||||||
|
|
||||||
// For MariaDb
|
|
||||||
Future<void> configureServer(Angel app) async {
|
|
||||||
try {
|
|
||||||
var connection = await connectToMariaDb(app.configuration);
|
|
||||||
var executor = MariaDbExecutor(connection, logger: app.logger);
|
|
||||||
|
|
||||||
app
|
|
||||||
..container.registerSingleton<QueryExecutor>(executor)
|
|
||||||
..shutdownHooks.add((_) => connection.close());
|
|
||||||
} catch (e) {
|
|
||||||
app.logger.severe("Failed to connect to MariaDB. ORM disabled.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MariaDB connection
|
|
||||||
Future<MySqlConnection> connectToMariaDb(Map configuration) async {
|
|
||||||
var mariaDbConfig = configuration['mysql'] as Map? ?? {};
|
|
||||||
var settings = ConnectionSettings(
|
|
||||||
host: mariaDbConfig['host'] as String? ?? 'localhost',
|
|
||||||
port: mariaDbConfig['port'] as int? ?? 3306,
|
|
||||||
db: mariaDbConfig['database_name'] as String? ??
|
|
||||||
Platform.environment['USER'] ??
|
|
||||||
Platform.environment['USERNAME'] ??
|
|
||||||
'',
|
|
||||||
user: mariaDbConfig['username'] as String?,
|
|
||||||
password: mariaDbConfig['password'] as String?,
|
|
||||||
timeout: Duration(
|
|
||||||
seconds: mariaDbConfig['timeout_in_seconds'] as int? ?? 30000),
|
|
||||||
useSSL: mariaDbConfig['use_ssl'] as bool? ?? false);
|
|
||||||
|
|
||||||
var connection = await MySqlConnection.connect(settings);
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For Mysql
|
|
||||||
/*
|
|
||||||
Future<void> configureServer(Angel app) async {
|
|
||||||
try {
|
|
||||||
var connection = await connectToMysql(app.configuration);
|
|
||||||
var executor = MySqlExecutor(connection, logger: app.logger);
|
|
||||||
|
|
||||||
app
|
|
||||||
..container.registerSingleton<QueryExecutor>(executor)
|
|
||||||
..shutdownHooks.add((_) => connection.close());
|
|
||||||
} catch (e) {
|
|
||||||
app.logger.severe("Failed to connect to MySQL. ORM disabled.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mysql Connection
|
|
||||||
Future<MySQLConnection> connectToMysql(Map configuration) async {
|
|
||||||
var mysqlConfig = configuration['mysql'] as Map? ?? {};
|
|
||||||
|
|
||||||
var connection = await MySQLConnection.createConnection(
|
|
||||||
host: mysqlConfig['host'] as String? ?? 'localhost',
|
|
||||||
port: mysqlConfig['port'] as int? ?? 3306,
|
|
||||||
databaseName: mysqlConfig['database_name'] as String? ??
|
|
||||||
Platform.environment['USER'] ??
|
|
||||||
Platform.environment['USERNAME'] ??
|
|
||||||
'',
|
|
||||||
userName: mysqlConfig['username'] as String? ?? '',
|
|
||||||
password: mysqlConfig['password'] as String? ?? '',
|
|
||||||
secure: mysqlConfig['use_ssl'] as bool? ?? false);
|
|
||||||
|
|
||||||
await connection.connect(timeoutMs: 10000);
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
*/
|
|
|
@ -1,8 +1,7 @@
|
||||||
|
/// Custom plugins go here.
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:angel3_framework/angel3_framework.dart';
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'orm.dart' as orm;
|
|
||||||
|
|
||||||
Future configureServer(Angel app) async {
|
Future configureServer(Angel app) async {
|
||||||
// Include any plugins you have made here.
|
// Include any plugins you have made here.
|
||||||
await app.configure(orm.configureServer);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
import 'package:angel3_migration/angel3_migration.dart';
|
|
||||||
import 'package:angel3_serialize/angel3_serialize.dart';
|
|
||||||
import 'package:angel3_orm/angel3_orm.dart';
|
|
||||||
import 'package:optional/optional.dart';
|
|
||||||
part 'greeting.g.dart';
|
|
||||||
|
|
||||||
@serializable
|
|
||||||
@orm
|
|
||||||
abstract class _Greeting extends Model {
|
|
||||||
@SerializableField(isNullable: false)
|
|
||||||
String? get message;
|
|
||||||
}
|
|
|
@ -1,281 +0,0 @@
|
||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of 'greeting.dart';
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// MigrationGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
class GreetingMigration extends Migration {
|
|
||||||
@override
|
|
||||||
void up(Schema schema) {
|
|
||||||
schema.create('greetings', (table) {
|
|
||||||
table.serial('id').primaryKey();
|
|
||||||
table.timeStamp('created_at');
|
|
||||||
table.timeStamp('updated_at');
|
|
||||||
table.varChar('message', length: 255);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void down(Schema schema) {
|
|
||||||
schema.drop('greetings');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// OrmGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
class GreetingQuery extends Query<Greeting, GreetingQueryWhere> {
|
|
||||||
GreetingQuery({Query? parent, Set<String>? trampoline})
|
|
||||||
: super(parent: parent) {
|
|
||||||
trampoline ??= <String>{};
|
|
||||||
trampoline.add(tableName);
|
|
||||||
_where = GreetingQueryWhere(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
final GreetingQueryValues values = GreetingQueryValues();
|
|
||||||
|
|
||||||
List<String> _selectedFields = [];
|
|
||||||
|
|
||||||
GreetingQueryWhere? _where;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Map<String, String> get casts {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get tableName {
|
|
||||||
return 'greetings';
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<String> get fields {
|
|
||||||
const _fields = ['id', 'created_at', 'updated_at', 'message'];
|
|
||||||
return _selectedFields.isEmpty
|
|
||||||
? _fields
|
|
||||||
: _fields.where((field) => _selectedFields.contains(field)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
GreetingQuery select(List<String> selectedFields) {
|
|
||||||
_selectedFields = selectedFields;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
GreetingQueryWhere? get where {
|
|
||||||
return _where;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
GreetingQueryWhere newWhereClause() {
|
|
||||||
return GreetingQueryWhere(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
Optional<Greeting> parseRow(List row) {
|
|
||||||
if (row.every((x) => x == null)) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
var model = Greeting(
|
|
||||||
id: fields.contains('id') ? row[0].toString() : null,
|
|
||||||
createdAt: fields.contains('created_at') ? (row[1] as DateTime?) : null,
|
|
||||||
updatedAt: fields.contains('updated_at') ? (row[2] as DateTime?) : null,
|
|
||||||
message: fields.contains('message') ? (row[3] as String?) : null);
|
|
||||||
return Optional.of(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Optional<Greeting> deserialize(List row) {
|
|
||||||
return parseRow(row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class GreetingQueryWhere extends QueryWhere {
|
|
||||||
GreetingQueryWhere(GreetingQuery query)
|
|
||||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
|
||||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
|
||||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
|
||||||
message = StringSqlExpressionBuilder(query, 'message');
|
|
||||||
|
|
||||||
final NumericSqlExpressionBuilder<int> id;
|
|
||||||
|
|
||||||
final DateTimeSqlExpressionBuilder createdAt;
|
|
||||||
|
|
||||||
final DateTimeSqlExpressionBuilder updatedAt;
|
|
||||||
|
|
||||||
final StringSqlExpressionBuilder message;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<SqlExpressionBuilder> get expressionBuilders {
|
|
||||||
return [id, createdAt, updatedAt, message];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class GreetingQueryValues extends MapQueryValues {
|
|
||||||
@override
|
|
||||||
Map<String, String> get casts {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
String? get id {
|
|
||||||
return (values['id'] as String?);
|
|
||||||
}
|
|
||||||
|
|
||||||
set id(String? value) => values['id'] = 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 updatedAt(DateTime? value) => values['updated_at'] = value;
|
|
||||||
String? get message {
|
|
||||||
return (values['message'] as String?);
|
|
||||||
}
|
|
||||||
|
|
||||||
set message(String? value) => values['message'] = value;
|
|
||||||
void copyFrom(Greeting model) {
|
|
||||||
createdAt = model.createdAt;
|
|
||||||
updatedAt = model.updatedAt;
|
|
||||||
message = model.message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// JsonModelGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
@generatedSerializable
|
|
||||||
class Greeting extends _Greeting {
|
|
||||||
Greeting({this.id, this.createdAt, this.updatedAt, required this.message});
|
|
||||||
|
|
||||||
/// A unique identifier corresponding to this item.
|
|
||||||
@override
|
|
||||||
String? id;
|
|
||||||
|
|
||||||
/// The time at which this item was created.
|
|
||||||
@override
|
|
||||||
DateTime? createdAt;
|
|
||||||
|
|
||||||
/// The last time at which this item was updated.
|
|
||||||
@override
|
|
||||||
DateTime? updatedAt;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String? message;
|
|
||||||
|
|
||||||
Greeting copyWith(
|
|
||||||
{String? id, DateTime? createdAt, DateTime? updatedAt, String? message}) {
|
|
||||||
return Greeting(
|
|
||||||
id: id ?? this.id,
|
|
||||||
createdAt: createdAt ?? this.createdAt,
|
|
||||||
updatedAt: updatedAt ?? this.updatedAt,
|
|
||||||
message: message ?? this.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(other) {
|
|
||||||
return other is _Greeting &&
|
|
||||||
other.id == id &&
|
|
||||||
other.createdAt == createdAt &&
|
|
||||||
other.updatedAt == updatedAt &&
|
|
||||||
other.message == message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode {
|
|
||||||
return hashObjects([id, createdAt, updatedAt, message]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return 'Greeting(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, message=$message)';
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
return GreetingSerializer.toMap(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// SerializerGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
const GreetingSerializer greetingSerializer = GreetingSerializer();
|
|
||||||
|
|
||||||
class GreetingEncoder extends Converter<Greeting, Map> {
|
|
||||||
const GreetingEncoder();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Map convert(Greeting model) => GreetingSerializer.toMap(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
class GreetingDecoder extends Converter<Map, Greeting> {
|
|
||||||
const GreetingDecoder();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Greeting convert(Map map) => GreetingSerializer.fromMap(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
class GreetingSerializer extends Codec<Greeting, Map> {
|
|
||||||
const GreetingSerializer();
|
|
||||||
|
|
||||||
@override
|
|
||||||
GreetingEncoder get encoder => const GreetingEncoder();
|
|
||||||
@override
|
|
||||||
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?,
|
|
||||||
createdAt: map['created_at'] != null
|
|
||||||
? (map['created_at'] is 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)
|
|
||||||
: DateTime.parse(map['updated_at'].toString()))
|
|
||||||
: null,
|
|
||||||
message: map['message'] as String?);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Map<String, dynamic> toMap(_Greeting? model) {
|
|
||||||
if (model == null) {
|
|
||||||
throw FormatException("Required field [model] cannot be null");
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
'id': model.id,
|
|
||||||
'created_at': model.createdAt?.toIso8601String(),
|
|
||||||
'updated_at': model.updatedAt?.toIso8601String(),
|
|
||||||
'message': model.message
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class GreetingFields {
|
|
||||||
static const List<String> allFields = <String>[
|
|
||||||
id,
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
message
|
|
||||||
];
|
|
||||||
|
|
||||||
static const String id = 'id';
|
|
||||||
|
|
||||||
static const String createdAt = 'created_at';
|
|
||||||
|
|
||||||
static const String updatedAt = 'updated_at';
|
|
||||||
|
|
||||||
static const String message = 'message';
|
|
||||||
}
|
|
|
@ -1,9 +1,8 @@
|
||||||
|
/// This app's route configuration.
|
||||||
import 'package:angel3_framework/angel3_framework.dart';
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_orm/angel3_orm.dart';
|
|
||||||
import 'package:angel3_static/angel3_static.dart';
|
import 'package:angel3_static/angel3_static.dart';
|
||||||
import 'package:file/file.dart';
|
import 'package:file/file.dart';
|
||||||
import 'controllers/controllers.dart' as controllers;
|
import 'controllers/controllers.dart' as controllers;
|
||||||
import '../models/greeting.dart';
|
|
||||||
|
|
||||||
/// Put your app routes here!
|
/// Put your app routes here!
|
||||||
///
|
///
|
||||||
|
@ -18,33 +17,6 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
|
||||||
// Render `views/hello.jl` when a user visits the application root.
|
// Render `views/hello.jl` when a user visits the application root.
|
||||||
app.get('/', (req, res) => res.render('hello'));
|
app.get('/', (req, res) => res.render('hello'));
|
||||||
|
|
||||||
app.get('/greetings', (req, res) {
|
|
||||||
var executor = req.container!.make<QueryExecutor>();
|
|
||||||
var query = GreetingQuery();
|
|
||||||
return query.get(executor);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post('/greetings', (req, res) async {
|
|
||||||
await req.parseBody();
|
|
||||||
|
|
||||||
if (!req.bodyAsMap.containsKey('message')) {
|
|
||||||
throw AngelHttpException.badRequest(message: 'Missing "message".');
|
|
||||||
} else {
|
|
||||||
var executor = req.container!.make<QueryExecutor>();
|
|
||||||
var message = req.bodyAsMap['message'].toString();
|
|
||||||
var query = GreetingQuery()..values.message = message;
|
|
||||||
var optional = await query.insert(executor);
|
|
||||||
return optional.value;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
return query.get(executor);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Mount static server at web in development.
|
// Mount static server at web in development.
|
||||||
// The `CachingVirtualDirectory` variant of `VirtualDirectory` also sends `Cache-Control` headers.
|
// The `CachingVirtualDirectory` variant of `VirtualDirectory` also sends `Cache-Control` headers.
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/// Declare services here!
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:angel3_framework/angel3_framework.dart';
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
|
|
||||||
|
|
40
pubspec.yaml
40
pubspec.yaml
|
@ -1,31 +1,25 @@
|
||||||
name: angel
|
name: angel
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
description: An ORM starter application for Angel3 framework
|
description: A basic starter application template for Angel3 framework
|
||||||
publish_to: none
|
publish_to: none
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.0.0 <4.0.0'
|
sdk: '>=2.16.0 <3.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
angel3_auth: ^8.0.0
|
angel3_auth: ^6.0.0
|
||||||
angel3_configuration: ^8.0.0
|
angel3_configuration: ^6.0.0
|
||||||
angel3_framework: ^8.0.0
|
angel3_framework: ^6.0.0
|
||||||
angel3_jael: ^8.0.0
|
angel3_jael: ^6.0.0
|
||||||
angel3_migration: ^8.0.0
|
angel3_production: ^6.0.0
|
||||||
angel3_orm: ^8.0.0
|
angel3_static: ^6.0.0
|
||||||
angel3_orm_mysql: ^8.0.0
|
angel3_validate: ^6.0.0
|
||||||
angel3_serialize: ^8.0.0
|
belatuk_pretty_logging: ^4.0.0
|
||||||
angel3_production: ^8.0.0
|
|
||||||
angel3_static: ^8.0.0
|
|
||||||
angel3_validate: ^8.0.0
|
|
||||||
belatuk_pretty_logging: ^6.0.0
|
|
||||||
optional: ^6.0.0
|
|
||||||
logging: ^1.0.0
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
angel3_hot: ^8.0.0
|
angel3_hot: ^6.0.0
|
||||||
angel3_migration_runner: ^8.0.0
|
angel3_test: ^6.0.0
|
||||||
angel3_orm_generator: ^8.0.0
|
|
||||||
angel3_serialize_generator: ^8.0.0
|
|
||||||
angel3_test: ^8.0.0
|
|
||||||
build_runner: ^2.0.3
|
|
||||||
io: ^1.0.0
|
io: ^1.0.0
|
||||||
test: ^1.21.0
|
test: ^1.21.0
|
||||||
lints: ^2.1.1
|
lints: ^1.0.0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:angel/angel.dart';
|
|
||||||
import 'package:angel3_framework/angel3_framework.dart';
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_test/angel3_test.dart';
|
import 'package:angel3_test/angel3_test.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
import 'package:angel/angel.dart';
|
||||||
|
|
||||||
// Angel also includes facilities to make testing easier.
|
// Angel also includes facilities to make testing easier.
|
||||||
//
|
//
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
<head>
|
<head>
|
||||||
<title>{{ title ?? 'Angel' }}</title>
|
<title>{{ title ?? 'Angel' }}</title>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Lato:100" >
|
<link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
|
||||||
<link rel="stylesheet" type="text/css" href="/css/site.css">
|
<link rel="stylesheet" href="/css/site.css">
|
||||||
<link rel="icon" href="/images/favicon.png">
|
<link rel="icon" href="/images/favicon.png">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
Loading…
Reference in a new issue