Compare commits
34 commits
master
...
v6/angel3-
Author | SHA1 | Date | |
---|---|---|---|
|
5ac098e3f5 | ||
|
b1bd5c341e | ||
|
b5fea5806d | ||
|
290b018ab9 | ||
|
65f62b75c0 | ||
|
3b67c9670d | ||
|
7401143635 | ||
|
8e00405e2e | ||
|
b120ba505f | ||
|
fab33a543c | ||
|
a32652b683 | ||
|
9eb81a541d | ||
|
9697137ae8 | ||
|
d11df03d97 | ||
|
636f33de37 | ||
|
bf9bf67fa8 | ||
|
a32bb29af6 | ||
|
10192bd29a | ||
|
233f10b384 | ||
|
54afecd3bc | ||
|
1482cb2ff7 | ||
|
007f926f1b | ||
|
514b697b00 | ||
|
ece9e5d4fa | ||
|
0d0cb707c2 | ||
|
ffbc93c668 | ||
|
5186ae8111 | ||
|
91ff5f4e11 | ||
|
772f74a908 | ||
|
850ccb71b1 | ||
|
a3d80686b4 | ||
|
d42dd2befb | ||
|
478d45bf47 | ||
|
84f5ae5403 |
31 changed files with 564 additions and 258 deletions
|
@ -1,10 +1,11 @@
|
|||
.dart_tool
|
||||
.idea
|
||||
.pub
|
||||
.vscode
|
||||
.metals
|
||||
.git
|
||||
.github
|
||||
.packages
|
||||
logs/
|
||||
test/
|
||||
build/
|
||||
.analysis-options
|
||||
.packages
|
||||
*.g.dart
|
||||
pubspec.lock
|
3
.github/FUNDING.yml
vendored
3
.github/FUNDING.yml
vendored
|
@ -1,3 +0,0 @@
|
|||
# These are supported funding model platforms
|
||||
|
||||
github: [thosakwe]
|
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -78,7 +78,7 @@ crashlytics-build.properties
|
|||
fabric.properties
|
||||
|
||||
### VSCode template
|
||||
.vscode/*
|
||||
.vscode/
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
|
@ -88,3 +88,5 @@ logs/
|
|||
*.pem
|
||||
.DS_Store
|
||||
server_log.txt
|
||||
|
||||
.metals/
|
||||
|
|
|
@ -1,16 +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$/temp" />
|
||||
<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>
|
|
@ -1,28 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
<component name="ProjectInspectionProfilesVisibleTreeState">
|
||||
<entry key="Project Default">
|
||||
<profile-state>
|
||||
<expanded-state>
|
||||
<State>
|
||||
<id />
|
||||
</State>
|
||||
<State>
|
||||
<id>General</id>
|
||||
</State>
|
||||
<State>
|
||||
<id>XPath</id>
|
||||
</State>
|
||||
</expanded-state>
|
||||
<selected-state>
|
||||
<State>
|
||||
<id>AngularJS</id>
|
||||
</State>
|
||||
</selected-state>
|
||||
</profile-state>
|
||||
</entry>
|
||||
</component>
|
||||
</project>
|
|
@ -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.iml" filepath="$PROJECT_DIR$/.idea/angel.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -1,8 +0,0 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="dev.dart" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true" nameIsGenerated="true">
|
||||
<option name="VMOptions" value="--observe" />
|
||||
<option name="filePath" value="$PROJECT_DIR$/bin/dev.dart" />
|
||||
<option name="workingDirectory" value="$PROJECT_DIR$" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
|
@ -1,11 +0,0 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="prod.dart" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true" nameIsGenerated="true">
|
||||
<option name="checkedMode" value="false" />
|
||||
<option name="envs">
|
||||
<entry key="ANGEL_ENV" value="production" />
|
||||
</option>
|
||||
<option name="filePath" value="$PROJECT_DIR$/bin/prod.dart" />
|
||||
<option name="workingDirectory" value="$PROJECT_DIR$" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Change Log
|
||||
|
||||
## 1.0.0
|
||||
|
||||
* Initial version
|
24
Dockerfile
24
Dockerfile
|
@ -1,14 +1,24 @@
|
|||
FROM google/dart:latest
|
||||
FROM dart:latest
|
||||
|
||||
COPY ./ ./
|
||||
# Copy all the source code
|
||||
COPY ./config /app/config
|
||||
COPY ./lib /app/lib
|
||||
COPY ./bin /app/bin
|
||||
COPY ./views /app/views
|
||||
COPY ./web /app/web
|
||||
COPY ./*.yaml /app/
|
||||
|
||||
# Install dependencies, pre-build
|
||||
RUN pub get
|
||||
WORKDIR /app
|
||||
RUN dart pub upgrade
|
||||
|
||||
# Optionally build generaed sources.
|
||||
# Optionally build generated sources.
|
||||
# RUN pub run build_runner build
|
||||
|
||||
# Set environment, start server
|
||||
# Set environment, start server in JIT mode
|
||||
ENV ANGEL_ENV=production
|
||||
EXPOSE 3000
|
||||
CMD dart bin/prod.dart
|
||||
CMD dart ./bin/prod.dart -p 3000 -a 0.0.0.0
|
||||
|
||||
# Use -j flag to set higher number of isolates
|
||||
#CMD dart ./bin/prod.dart -p 3000 -a 0.0.0.0 -j 50
|
||||
|
||||
|
|
42
LICENSE
42
LICENSE
|
@ -1,21 +1,29 @@
|
|||
The MIT License (MIT)
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2016 angel-dart
|
||||
Copyright (c) 2021, dukefirehawk.com
|
||||
All rights reserved.
|
||||
|
||||
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:
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
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.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
|
106
README.md
106
README.md
|
@ -1,60 +1,80 @@
|
|||
[![The Angel Framework](https://angel-dart.github.io/assets/images/logo.png)](https://angel-dart.dev)
|
||||
# ORM Starter Application for Angel3 framework
|
||||
|
||||
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/angel_dart/discussion)
|
||||
[![Pub](https://img.shields.io/pub/v/angel_framework.svg)](https://pub.dartlang.org/packages/angel_framework)
|
||||
[![Build status](https://travis-ci.org/angel-dart/framework.svg?branch=master)](https://travis-ci.org/angel-dart/framework)
|
||||
![License](https://img.shields.io/github/license/angel-dart/framework.svg)
|
||||
|
||||
**A polished, production-ready backend framework in Dart.**
|
||||
|
||||
*Note: This repo is an application boilerplate ,and not the underlying framework library.*
|
||||
|
||||
-----
|
||||
## About
|
||||
Angel is a full-stack Web framework in Dart. It aims to
|
||||
streamline development by providing many common features
|
||||
out-of-the-box in a consistent manner.
|
||||
|
||||
With features like the following, Angel is the all-in-one framework you should choose to build your next project:
|
||||
* [GraphQL Support](https://github.com/angel-dart/graphql)
|
||||
* [PostgreSQL ORM](https://github.com/angel-dart/orm)
|
||||
* [Dependency Injection](https://docs.angel-dart.dev/guides/dependency-injection)
|
||||
* And [much more](https://github.com/angel-dart)...
|
||||
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 `postgresql`. `mysql` support is still in active development.
|
||||
|
||||
## Installation & Setup
|
||||
|
||||
Once you have [Dart](https://www.dartlang.org/) installed, bootstrapping a project is as simple as running a few shell commands:
|
||||
1. Download and install [Dart](https://dart.dev/get-dart).
|
||||
2. Install `postgresql` version 10, 11, 12 and 13
|
||||
3. Create a new user and database in postgres using `psql` cli. For example:
|
||||
|
||||
Install the [Angel CLI](https://github.com/angel-dart/cli):
|
||||
```sql
|
||||
postgres=# create database appdb;
|
||||
postgres=# create user appuser with encrypted password 'App1970#';
|
||||
postgres=# grant all privileges on database appdb to appuser;
|
||||
```
|
||||
|
||||
```bash
|
||||
pub global activate angel_cli
|
||||
```
|
||||
4. Update the `postgres` section in the `config/default.yaml` file with the newly created user and database name.
|
||||
|
||||
Bootstrap a project:
|
||||
```yaml
|
||||
postgres:
|
||||
host: localhost
|
||||
port: 5432
|
||||
database_name: appdb
|
||||
username: appuser
|
||||
password: App1970#
|
||||
useSSL: false
|
||||
time_zone: UTC
|
||||
```
|
||||
|
||||
```bash
|
||||
angel init hello
|
||||
```
|
||||
5. Run the migration to generate `migrations` and `greetings` tables in the database.
|
||||
|
||||
You can even have your server run and be *hot-reloaded* on file changes:
|
||||
```bash
|
||||
dart bin/migrate.dart up
|
||||
```
|
||||
|
||||
```bash
|
||||
dart --observe bin/dev.dart
|
||||
```
|
||||
### Development
|
||||
|
||||
Next, check out the [detailed documentation](https://docs.angel-dart.dev/v/2.x) to learn to flesh out your project.
|
||||
1. Run the following command to start Angel3 server in dev mode to *hot-reloaded* on file changes:
|
||||
|
||||
## Examples and Documentation
|
||||
Visit the [documentation](https://docs.angel-dart.dev/v/2.x)
|
||||
for dozens of guides and resources, including video tutorials,
|
||||
to get up and running as quickly as possible with Angel.
|
||||
```bash
|
||||
dart --observe bin/dev.dart
|
||||
```
|
||||
|
||||
Examples and complete projects can be found
|
||||
[here](https://github.com/angel-dart/examples-v2).
|
||||
2. Modify the code and watch the changes applied to the application
|
||||
|
||||
3. Insert a message into DB:
|
||||
|
||||
You can also view the [API Documentation](http://www.dartdocs.org/documentation/angel_framework/latest).
|
||||
```bash
|
||||
curl -H "Content-Type: application/json" -X POST -d '{"message":"OK_Message" }' "http://localhost:3000/greetings/"
|
||||
```
|
||||
|
||||
There is also an [Awesome Angel :fire:](https://github.com/angel-dart/awesome-angel) list.
|
||||
or
|
||||
|
||||
```bash
|
||||
curl -X POST -d 'message=OK_Message2' "http://localhost:3000/greetings/"
|
||||
```
|
||||
|
||||
4. Query DB:
|
||||
|
||||
```
|
||||
http://localhost:3000/greetings/
|
||||
```
|
||||
|
||||
### Production
|
||||
|
||||
1. Run the following command:
|
||||
|
||||
```bash
|
||||
dart bin/prod.dart
|
||||
```
|
||||
|
||||
2. Run as docker. Edit and run the provided `Dockerfile` to build the image.
|
||||
|
||||
## 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.
|
||||
|
||||
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,8 +1 @@
|
|||
include: package:pedantic/analysis_options.yaml
|
||||
analyzer:
|
||||
strong-mode:
|
||||
implicit-casts: false
|
||||
linter:
|
||||
rules:
|
||||
- unnecessary_const
|
||||
- unnecessary_new
|
||||
include: package:lints/recommended.yaml
|
||||
|
|
14
bin/dev.dart
14
bin/dev.dart
|
@ -1,17 +1,17 @@
|
|||
import 'dart:io';
|
||||
import 'package:angel/src/pretty_logging.dart';
|
||||
import 'package:angel/angel.dart';
|
||||
import 'package:angel_container/mirrors.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_hot/angel_hot.dart';
|
||||
import 'package:belatuk_pretty_logging/belatuk_pretty_logging.dart';
|
||||
import 'package:angel3_container/mirrors.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:angel3_hot/angel3_hot.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
main() async {
|
||||
void main() async {
|
||||
// Watch the config/ and web/ directories for changes, and hot-reload the server.
|
||||
hierarchicalLoggingEnabled = true;
|
||||
|
||||
var hot = HotReloader(() async {
|
||||
var logger = Logger.detached('{{angel}}')
|
||||
var logger = Logger.detached('Angel3')
|
||||
..level = Level.ALL
|
||||
..onRecord.listen(prettyLog);
|
||||
var app = Angel(logger: logger, reflector: MirrorsReflector());
|
||||
|
@ -24,5 +24,5 @@ main() async {
|
|||
|
||||
var server = await hot.startServer('127.0.0.1', 3000);
|
||||
print(
|
||||
'{{angel}} server listening at http://${server.address.address}:${server.port}');
|
||||
'[angel] server listening at http://${server.address.address}:${server.port}');
|
||||
}
|
||||
|
|
28
bin/migrate.dart
Normal file
28
bin/migrate.dart
Normal file
|
@ -0,0 +1,28 @@
|
|||
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/postgres.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);
|
||||
var connection = await connectToPostgres(configuration);
|
||||
var migrationRunner = PostgresMigrationRunner(connection, migrations: [
|
||||
GreetingMigration(),
|
||||
]);
|
||||
return await runMigrations(migrationRunner, args);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:angel/angel.dart';
|
||||
import 'package:angel_container/mirrors.dart';
|
||||
import 'package:angel_production/angel_production.dart';
|
||||
import 'package:angel3_container/mirrors.dart';
|
||||
import 'package:angel3_production/angel3_production.dart';
|
||||
|
||||
// NOTE: By default, the Runner class does not use the `MirrorsReflector`, or any
|
||||
// reflector, by default.
|
||||
|
@ -17,7 +17,7 @@ import 'package:angel_production/angel_production.dart';
|
|||
// so use it if possible.
|
||||
//
|
||||
// However, the following alternatives exist:
|
||||
// * Generation via `package:angel_container_generator`
|
||||
// * Generation via `package:angel3_container_generator`
|
||||
// * Creating an instance of `StaticReflector`
|
||||
// * Manually implementing the `Reflector` interface (cumbersome; not recommended)
|
||||
//
|
||||
|
@ -25,6 +25,5 @@ import 'package:angel_production/angel_production.dart';
|
|||
// so in the meantime, visit the Angel chat for further questions:
|
||||
//
|
||||
// https://gitter.im/angel_dart/discussion
|
||||
main(List<String> args) =>
|
||||
Runner('{{angel}}', configureServer, reflector: MirrorsReflector())
|
||||
.run(args);
|
||||
void main(List<String> args) =>
|
||||
Runner('Angel3', configureServer, reflector: MirrorsReflector()).run(args);
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
# Default server configuration.
|
||||
jwt_secret: INSECURE_DEFAULT_SECRET
|
||||
host: 127.0.0.1
|
||||
mongo_db: mongodb://localhost:27017/angel
|
||||
port: 3000
|
||||
postgres:
|
||||
host: localhost
|
||||
port: 5432
|
||||
database_name: appdb
|
||||
username: appuser
|
||||
password: App1970#
|
||||
useSSL: false
|
||||
time_zone: UTC
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/// Your very own web application!
|
||||
library angel;
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:file/local.dart';
|
||||
import 'src/config/config.dart' as configuration;
|
||||
import 'src/routes/routes.dart' as routes;
|
||||
|
|
1
lib/models.dart
Normal file
1
lib/models.dart
Normal file
|
@ -0,0 +1 @@
|
|||
export 'src/models/greeting.dart';
|
|
@ -1,9 +1,6 @@
|
|||
/// Configuration for this Angel instance.
|
||||
library angel.src.config;
|
||||
|
||||
import 'package:angel_configuration/angel_configuration.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_jael/angel_jael.dart';
|
||||
import 'package:angel3_configuration/angel3_configuration.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:angel3_jael/angel3_jael.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'plugins/plugins.dart' as plugins;
|
||||
|
||||
|
|
38
lib/src/config/plugins/orm.dart
Normal file
38
lib/src/config/plugins/orm.dart
Normal file
|
@ -0,0 +1,38 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:angel3_orm/angel3_orm.dart';
|
||||
import 'package:angel3_orm_postgres/angel3_orm_postgres.dart';
|
||||
import 'package:postgres/postgres.dart';
|
||||
|
||||
Future<void> configureServer(Angel app) async {
|
||||
try {
|
||||
var connection = await connectToPostgres(app.configuration);
|
||||
await connection.open();
|
||||
|
||||
var executor = PostgreSqlExecutor(connection, logger: app.logger);
|
||||
|
||||
app
|
||||
..container.registerSingleton<QueryExecutor>(executor)
|
||||
..shutdownHooks.add((_) => connection.close());
|
||||
} catch (e) {
|
||||
app.logger.severe("Failed to connect to PostgreSQL. ORM disabled.", e);
|
||||
}
|
||||
}
|
||||
|
||||
Future<PostgreSQLConnection> connectToPostgres(Map configuration) async {
|
||||
var postgresConfig = configuration['postgres'] as Map? ?? {};
|
||||
var connection = PostgreSQLConnection(
|
||||
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);
|
||||
return connection;
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
/// Custom plugins go here.
|
||||
library angel.src.config.plugins;
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'orm.dart' as orm;
|
||||
|
||||
Future configureServer(Angel app) async {
|
||||
// Include any plugins you have made here.
|
||||
await app.configure(orm.configureServer);
|
||||
}
|
||||
|
|
12
lib/src/models/greeting.dart
Normal file
12
lib/src/models/greeting.dart
Normal file
|
@ -0,0 +1,12 @@
|
|||
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;
|
||||
}
|
267
lib/src/models/greeting.g.dart
Normal file
267
lib/src/models/greeting.g.dart
Normal file
|
@ -0,0 +1,267 @@
|
|||
// 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.varChar('message');
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void down(Schema schema) {
|
||||
schema.drop('greetings');
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class GreetingQuery extends Query<Greeting, GreetingQueryWhere> {
|
||||
GreetingQuery({Set<String>? trampoline}) {
|
||||
trampoline ??= <String>{};
|
||||
trampoline.add(tableName);
|
||||
_where = GreetingQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final GreetingQueryValues values = GreetingQueryValues();
|
||||
|
||||
GreetingQueryWhere? _where;
|
||||
|
||||
@override
|
||||
Map<String, String> get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
String get tableName {
|
||||
return 'greetings';
|
||||
}
|
||||
|
||||
@override
|
||||
List<String> get fields {
|
||||
return const ['id', 'message', 'created_at', 'updated_at'];
|
||||
}
|
||||
|
||||
@override
|
||||
GreetingQueryWhere? get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
GreetingQueryWhere newWhereClause() {
|
||||
return GreetingQueryWhere(this);
|
||||
}
|
||||
|
||||
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?));
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
Optional<Greeting> deserialize(List row) {
|
||||
return Optional.ofNullable(parseRow(row));
|
||||
}
|
||||
}
|
||||
|
||||
class GreetingQueryWhere extends QueryWhere {
|
||||
GreetingQueryWhere(GreetingQuery query)
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
message = StringSqlExpressionBuilder(query, 'message'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final StringSqlExpressionBuilder message;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
@override
|
||||
List<SqlExpressionBuilder> get expressionBuilders {
|
||||
return [id, message, createdAt, updatedAt];
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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 createdAt(DateTime? value) => values['created_at'] = value;
|
||||
DateTime? get updatedAt {
|
||||
return (values['updated_at'] as DateTime?);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime? value) => values['updated_at'] = value;
|
||||
void copyFrom(Greeting model) {
|
||||
message = model.message;
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonModelGenerator
|
||||
// **************************************************************************
|
||||
|
||||
@generatedSerializable
|
||||
class Greeting extends _Greeting {
|
||||
Greeting({this.id, required this.message, this.createdAt, this.updatedAt});
|
||||
|
||||
@override
|
||||
final String? id;
|
||||
|
||||
@override
|
||||
final String? message;
|
||||
|
||||
@override
|
||||
final DateTime? createdAt;
|
||||
|
||||
@override
|
||||
final DateTime? updatedAt;
|
||||
|
||||
Greeting copyWith(
|
||||
{String? id, String? message, DateTime? createdAt, DateTime? updatedAt}) {
|
||||
return Greeting(
|
||||
id: id ?? this.id,
|
||||
message: message ?? this.message,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
return other is _Greeting &&
|
||||
other.id == id &&
|
||||
other.message == message &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([id, message, createdAt, updatedAt]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Greeting(id=$id, message=$message, createdAt=$createdAt, updatedAt=$updatedAt)';
|
||||
}
|
||||
|
||||
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?,
|
||||
message: map['message'] 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);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Greeting model) {
|
||||
if (model.message == null) {
|
||||
throw FormatException("Missing required field 'message' on Greeting.");
|
||||
}
|
||||
|
||||
return {
|
||||
'id': model.id,
|
||||
'message': model.message,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class GreetingFields {
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
message,
|
||||
createdAt,
|
||||
updatedAt
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String message = 'message';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
import 'package:angel_http_exception/angel_http_exception.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:io/ansi.dart';
|
||||
|
||||
/// Prints the contents of a [LogRecord] with pretty colors.
|
||||
void prettyLog(LogRecord record) {
|
||||
var code = chooseLogColor(record.level);
|
||||
|
||||
if (record.error == null) print(code.wrap(record.toString()));
|
||||
|
||||
if (record.error != null) {
|
||||
var err = record.error;
|
||||
if (err is AngelHttpException && err.statusCode != 500) return;
|
||||
print(code.wrap(record.toString() + '\n'));
|
||||
print(code.wrap(err.toString()));
|
||||
|
||||
if (record.stackTrace != null) {
|
||||
print(code.wrap(record.stackTrace.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Chooses a color based on the logger [level].
|
||||
AnsiCode chooseLogColor(Level level) {
|
||||
if (level == Level.SHOUT)
|
||||
return backgroundRed;
|
||||
else if (level == Level.SEVERE)
|
||||
return red;
|
||||
else if (level == Level.WARNING)
|
||||
return yellow;
|
||||
else if (level == Level.INFO)
|
||||
return cyan;
|
||||
else if (level == Level.CONFIG ||
|
||||
level == Level.FINE ||
|
||||
level == Level.FINER ||
|
||||
level == Level.FINEST) return lightGray;
|
||||
return resetAll;
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
library angel.src.routes.controllers;
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
|
||||
Future configureServer(Angel app) async {
|
||||
/// Controllers will not function unless wired to the application!
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
/// This app's route configuration.
|
||||
library angel.src.routes;
|
||||
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_static/angel_static.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:angel3_orm/angel3_orm.dart';
|
||||
import 'package:angel3_static/angel3_static.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'controllers/controllers.dart' as controllers;
|
||||
import '../models/greeting.dart';
|
||||
|
||||
/// Put your app routes here!
|
||||
///
|
||||
/// See the wiki for information about routing, requests, and responses:
|
||||
/// * https://github.com/angel-dart/angel/wiki/Basic-Routing
|
||||
/// * https://github.com/angel-dart/angel/wiki/Requests-&-Responses
|
||||
/// * https://angel3-docs.dukefirehawk.com/guides/basic-routing
|
||||
/// * https://angel3-docs.dukefirehawk.com/guides/requests-and-responses
|
||||
AngelConfigurer configureServer(FileSystem fileSystem) {
|
||||
return (Angel app) async {
|
||||
// Typically, you want to mount controllers first, after any global middleware.
|
||||
|
@ -19,6 +18,33 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
|
|||
// Render `views/hello.jl` when a user visits the application root.
|
||||
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.
|
||||
// The `CachingVirtualDirectory` variant of `VirtualDirectory` also sends `Cache-Control` headers.
|
||||
//
|
||||
|
@ -27,7 +53,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
|
|||
//
|
||||
// Read the following two sources for documentation:
|
||||
// * https://medium.com/the-angel-framework/serving-static-files-with-the-angel-framework-2ddc7a2b84ae
|
||||
// * https://github.com/angel-dart/static
|
||||
// * https://pub.dev/packages/angel3_static
|
||||
if (!app.environment.isProduction) {
|
||||
var vDir = VirtualDirectory(
|
||||
app,
|
||||
|
@ -43,7 +69,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
|
|||
// Set our application up to handle different errors.
|
||||
//
|
||||
// Read the following for documentation:
|
||||
// * https://github.com/angel-dart/angel/wiki/Error-Handling
|
||||
// * https://angel3-docs.dukefirehawk.com/guides/error-handling
|
||||
|
||||
var oldErrorHandler = app.errorHandler;
|
||||
app.errorHandler = (e, req, res) async {
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
/// Declare services here!
|
||||
library angel.services;
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
|
||||
/// Configure our application to use *services*.
|
||||
/// Services must be wired to the app via `app.use`.
|
||||
|
|
43
pubspec.yaml
43
pubspec.yaml
|
@ -1,20 +1,31 @@
|
|||
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! ;)
|
||||
version: 1.0.0
|
||||
description: An ORM starter application for Angel3 framework
|
||||
publish_to: none
|
||||
environment:
|
||||
sdk: '>=2.0.0-dev <3.0.0'
|
||||
homepage: https://github.com/angel-dart/angel
|
||||
sdk: '>=2.16.0 <3.0.0'
|
||||
dependencies:
|
||||
angel_auth: ^2.0.0 # Supports stateless authentication via JWT
|
||||
angel_configuration: ^2.0.0 # Loads application configuration, along with support for .env files.
|
||||
angel_framework: ^2.0.0 # The core server library.
|
||||
angel_jael: ^2.0.0 # Server-side templating engine
|
||||
angel_production: ^1.0.0 # Production application runner.
|
||||
angel_static: ^2.0.0 # Static file server
|
||||
angel_validate: ^2.0.0 # Allows for validation of input data
|
||||
angel3_auth: ^6.0.0
|
||||
angel3_configuration: ^6.0.0
|
||||
angel3_framework: ^6.0.0
|
||||
angel3_jael: ^6.0.0
|
||||
angel3_migration: ^6.0.0
|
||||
angel3_orm: ^6.0.0
|
||||
angel3_orm_postgres: ^6.0.0
|
||||
angel3_serialize: ^6.0.0
|
||||
angel3_production: ^6.0.0
|
||||
angel3_static: ^6.0.0
|
||||
angel3_validate: ^6.0.0
|
||||
belatuk_pretty_logging: ^4.0.0
|
||||
optional: ^6.0.0
|
||||
logging: ^1.0.0
|
||||
dev_dependencies:
|
||||
angel_hot: ^2.0.0 # Hot-reloading support. :)
|
||||
angel_test: ^2.0.0 # Utilities for testing Angel servers.
|
||||
io: ^0.3.2 # For pretty printing.
|
||||
pedantic: ^1.0.0 # Enforces Dart style conventions.
|
||||
test: ^1.0.0 # For unit testing.
|
||||
angel3_hot: ^6.0.0
|
||||
angel3_migration_runner: ^6.0.0
|
||||
angel3_orm_generator: ^6.0.0
|
||||
angel3_serialize_generator: ^6.0.0
|
||||
angel3_test: ^6.0.0
|
||||
build_runner: ^2.0.3
|
||||
io: ^1.0.0
|
||||
test: ^1.21.0
|
||||
lints: ^1.0.0
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:angel/angel.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_test/angel_test.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:angel3_test/angel3_test.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
// Angel also includes facilities to make testing easier.
|
||||
|
@ -19,8 +19,8 @@ import 'package:test/test.dart';
|
|||
// here:
|
||||
// https://github.com/dart-lang/test
|
||||
|
||||
main() async {
|
||||
TestClient client;
|
||||
void main() async {
|
||||
late TestClient client;
|
||||
|
||||
setUp(() async {
|
||||
var app = Angel();
|
||||
|
@ -35,7 +35,7 @@ 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));
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
<head>
|
||||
<title>{{ title ?? 'Angel' }}</title>
|
||||
|
||||
<link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="/css/site.css">
|
||||
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Lato:100" >
|
||||
<link rel="stylesheet" type="text/css" href="/css/site.css">
|
||||
<link rel="icon" href="/images/favicon.png">
|
||||
</head>
|
||||
<body>
|
||||
|
|
Loading…
Reference in a new issue