shelf_easy 3.5.2 shelf_easy: ^3.5.2 copied to clipboard
This library includes a json model generator, a unified database operator interface, a server and client framework, a virtual machine for AOT code push, and a log module.
Language: English | 中文
This library is a comprehensive lightweight framework, each module can be used independently. Example code directory example Reading navigation:
- 1. Data model generation module for Json serialization
- 2. Unified data operation module for Database
- 3. Web service module, Websocket service module, supporting client module
- 4. Dart subset virtual machine module, which can be used in Flutter's AOT environment
- 5. Log module
- 6. Language localization module
- 7. Server and client in cluster environment
1. Data model generation module for Json serialization #
Model generation #
The code to generate the Json serialized data model is in the generator.dart file in the example directory.
You can execute dart generator.dart
in the example directory to generate the model, and the generated files are in the model directory.
Serialization Demo #
The code demonstrating Json serialization and deserialization is in the test/test_model.dart file in the example directory.
You can execute dart test/test_model.dart
in the example directory to view the console output.
2. Unified data operation module for Database #
The code that demonstrates the unified operation of the database is in the test/test_database.dart file in the example directory.
You can execute dart test/test_database.dart
in the example directory to view the console output.
Notice:
-
The database auxiliary classes such as
UserQuery
generated by the serialization code generator combined with the unified database operation classEasyUniDb
can take advantage of the language advantages ofdart strong type
and avoidMap<String, dynamic>
orsql as much as possible Statement
s associatedstring key
operations. -
The interface style of
EasyUniDb
is basically consistent with that ofmongo shell
. Currently, it only supports Mongodb, and plans to support postgre. -
The sample code is just a demonstration. The result returned by each interface of
EasyUniDb
is an object of typeDbResult<T>
. In real scenarios, the status of the database operation result can be judged according to the field ofDbResult<T>
. For details, please refer to the annotations of the relevant classes.
3. Web service module, Websocket service module, supporting client module #
Web server #
The sample code of the web server is in the test/test_webserver.dart file in the example directory.
The web server can be started by executing dart test/test_webserver.dart
in the example directory.
Web client #
The sample code of the web client is in the test/test_webclient.dart file in the example directory.
You can execute dart test/test_webclient.dart
in the example directory to initiate a web client call.
Websocket server #
The sample code of the Websocket server is in the test/test_wssserver.dart file in the example directory.
You can execute dart test/test_wssserver.dart
in the example directory to start the Websocket server.
Websocket client #
The example code of the example Websocket client is in the test/test_wssclient.dart file in the example directory.
You can execute dart test/test_wssclient.dart
in the example directory to initiate a Websocket client call.
4. Dart subset virtual machine module, which can be used in Flutter's AOT environment #
Because the flutter environment cannot push code in the AOT environment, hot update has become a problem. Fortunately, dart officially provides the dart:analyzer
code analysis package, and this module is developed based on this package.
Generate virtual machine bridge type #
The code to generate the virtual machine bridge type is in the test/test_vmgen.dart file in the example directory.
Bridge types can be generated by executing dart test/test_vmgen.dart
in the example directory. The generated files are in the bridge directory.
Dart subset virtual machine usage #
The code for Dart subset virtual machine usage is in the test/test_vmware.dart file in the example directory.
You can execute dart test/test_vmware.dart
in the example directory to view the console output.
Dart code push solution in Flutter environment #
Dart network client library for ZyCloud service zycloud_client
Flutter widget library for ZyCloud service zycloud_widget
Notice:
-
Some syntaxes of the current virtual machine are not yet compatible, but the compatible syntax is sufficient to meet most requirements.
-
The author has used this solution to carry out project practice in the production environment. This practice project has achieved 99% of
dart
code push in the AOT environment.
5. Log module #
The code of the log module is in the test/test_logger.dart file in the example directory.
You can execute dart test/test_logger.dart
in the example directory to view the console output information.
6. Language localization module #
The code of the language localization module is in the test/test_locale.dart file in the example directory.
You can execute dart test/test_locale.dart
in the example directory to view the console output information.
7. Server and client in cluster environment #
Cluster server #
The code of the cluster server is in the app/app_server.dart file in the example directory.
Notice:
-
The example server contains two environment configurations:
develop
andrelease
. You can customize many environment configurations according to actual needs. -
The example server contains three service nodes, namely: Public Web service node http 、 Public Websocket service node outer 、 Internal business service node inner.
Cluster client #
The code of the cluster client is in the app/app_client.dart file in the example directory.
Test process #
-
Open a new console window and execute
dart app/app_server.dart
in the example directory to start the server -
Open a new console window and execute
dart app/app_client.dart 8001
in the example directory to start the persistent connection client of useraaa
grouped bycat
-
Open a new console window, and execute
dart app/app_client.dart 8002
in the example directory to start the long-term connection client of userbbb
grouped bycat
-
Open a new console window and execute
dart app/app_client.dart 8003
in the example directory to start the persistent connection client of userccc
of thedog
group. -
At this point, you can observe the output of each console window.
-
Open a new console window and execute
dart app/app_client.dart 8080
in the example directory to start thehttp
client to push data. -
At this point, you can observe the output of each console window.