首先确保已配置好
aqueduct
相关环境
在 ~/.pub_cache/bin
下新建 aqueduct_mysql
文件
cd ~/.pub_cache/bin
touch aquduct_mysql
在aqueduct_mysql
中写入:
# set aqueduct_mysql package's path
dart "xxxx/aqueduct_mysql/bin/aqueduct_mysql.dart" "$@"
# The VM exits with code 253 if the snapshot version is out-of-date.
# If it is, we need to delete it and run "pub global" manually.
exit_code=$?
if [ $exit_code != 253 ]; then
exit $exit_code
fi
给予aqueduct_mysql
执行权限:
chmod +x aqueduct_mysql
在项目中添加依赖:
dependencies:
aqueduct: ^3.3.0
aqueduct_mysql: ^0.0.1
- 生成
migration
文件:
aqueduct_mysql db generate
- 生成数据库
aqueduct_mysql db upgrade --connect mysql://username:password@host:port/databasename
- 添加认证client
aqueuct_mysql auth add-client --id newclient --connect mysql://username:password@host:port/databasename
- 使用
MySqlPersistentStore
final MySqlPersistentStore persistentStore = MySqlPersistentStore(
_config.database.username,
_config.database.password,
_config.database.host,
_config.database.port,
_config.database.databaseName);
context = ManagedContext(dataModel, persistentStore);
/// ......
final result= await Query(context, values: user).insert();