11import 'package:client/models/instances.dart' ;
22import 'package:client/repositories/instances/session_conn.dart' ;
3- import 'package:objectbox/objectbox.dart' ;
3+ // ignore: unnecessary_import
4+ import 'package:objectbox/objectbox.dart' ; // 必须引入, 不然objectbox不能正常使用
45import 'package:client/repositories/objectbox.g.dart' ;
56import 'package:client/repositories/repo.dart' ;
67import 'package:client/utils/active_set.dart' ;
@@ -28,9 +29,10 @@ class InstanceStorage {
2829
2930 /// 目的地址:目前支持 host:port 和 dbFile 两种类型
3031 String targetJson;
31-
32+
3233 /// 弃用,现在都存在 target 中
3334 String host;
35+
3436 /// 弃用,现在都存在 target 中
3537 int ? port;
3638
@@ -41,7 +43,7 @@ class InstanceStorage {
4143 /// 使用字符串类型存储 custom 的 json 字符串, 使用时进行 json 解析。 原因:ObjectBox 不支持 json 类型。
4244 /// 本来使用的 @Transient 注解加自定义类型,但是更新后好像失效,弃用了。
4345 String customJson;
44-
46+
4547 @Transient ()
4648 Map <String , String > get custom {
4749 if (customJson.isEmpty) {
@@ -71,7 +73,7 @@ class InstanceStorage {
7173 required int stDbType,
7274 required this .name,
7375 required this .targetJson,
74- required this .host,
76+ required this .host,
7577 this .port,
7678 required this .user,
7779 required this .password,
@@ -81,31 +83,30 @@ class InstanceStorage {
8183 ActiveSet <String >? activeSchemas,
8284 DateTime ? createdAt,
8385 DateTime ? latestOpenAt,
84- }) : activeSchemas = activeSchemas ?? ActiveSet <String >(List .empty ()),
85- dbType = DatabaseType .values[stDbType],
86- createdAt = createdAt ?? DateTime .now (),
87- latestOpenAt = latestOpenAt ?? DateTime (1970 , 1 , 1 ); //latestOpenAt 默认值未很早之前的时间
86+ }) : activeSchemas = activeSchemas ?? ActiveSet <String >(List .empty ()),
87+ dbType = DatabaseType .values[stDbType],
88+ createdAt = createdAt ?? DateTime .now (),
89+ latestOpenAt = latestOpenAt ?? DateTime (1970 , 1 , 1 ); //latestOpenAt 默认值未很早之前的时间
8890
8991 InstanceStorage .fromModel (InstanceModel model)
90- : id = model.id.value,
91- dbType = model.dbType,
92- name = model.name,
93- targetJson = jsonEncode (model.connectValue.target.toJson ()),
94- host = "deprecated" ,
95- user = model.user,
96- password = model.password,
97- desc = model.desc,
98- customJson = jsonEncode (model.custom),
99- initQuerys = model.initQuerys,
100- activeSchemas = ActiveSet <String >(model.activeSchemas),
101- createdAt = model.createdAt,
102- latestOpenAt = model.latestOpenAt;
92+ : id = model.id.value,
93+ dbType = model.dbType,
94+ name = model.name,
95+ targetJson = jsonEncode (model.connectValue.target.toJson ()),
96+ host = "deprecated" ,
97+ user = model.user,
98+ password = model.password,
99+ desc = model.desc,
100+ customJson = jsonEncode (model.custom),
101+ initQuerys = model.initQuerys,
102+ activeSchemas = ActiveSet <String >(model.activeSchemas),
103+ createdAt = model.createdAt,
104+ latestOpenAt = model.latestOpenAt;
103105
104106 ConnectTarget _parseTarget () {
105107 if (targetJson.trim ().isNotEmpty) {
106108 try {
107- return ConnectTarget .fromJson (
108- Map <String , dynamic >.from (jsonDecode (targetJson)));
109+ return ConnectTarget .fromJson (Map <String , dynamic >.from (jsonDecode (targetJson)));
109110 } catch (_) {
110111 return ConnectTarget .network (host: "" , port: port ?? 0 );
111112 }
@@ -162,21 +163,21 @@ class InstanceRepoImpl extends InstanceRepo {
162163 }
163164
164165 @override
165- // todo: aync
166+ // todo: aync
166167 bool isInstanceExist (String name) {
167168 final instance = getInstanceByName (name);
168169 return instance != null ;
169170 }
170171
171172 @override
172- // todo: aync
173+ // todo: aync
173174 InstanceModel ? getInstanceByName (String name) {
174175 final build = _instanceBox.query (InstanceStorage_ .name.equals (name)).build ();
175176 return build.findFirst ()? .toModel ();
176177 }
177178
178179 @override
179- // todo: 替换 getInstance
180+ // todo: 替换 getInstance
180181 InstanceModel ? getInstanceById (InstanceId id) {
181182 return _instanceBox.get (id.value)? .toModel ();
182183 }
0 commit comments