하얀설표 블로그




해결)It looks like you've created the database class Handle multiple times.





( 수정됨)


코드 예시

import 'package:example/Drift/insert.dart';

void a(){
  var db = Handle();
  db.close();
}
void main() async {
  a();
  a();
}

에러 메세지

WARNING (drift): It looks like you've created the database class Handle multiple times. When these two databases use the same QueryExecutor, race conditions will occur and might corrupt the database.
Try to follow the advice at https://drift.simonbinder.eu/faq/#using-the-database or, if you know what you're doing, set driftRuntimeOptions.dontWarnAboutMultipleDatabases = true
Here is the stacktrace from when the database was opened a second time:
#0      GeneratedDatabase._handleInstantiated (package:drift/src/runtime/api/db_base.dart:96:30)
#1      GeneratedDatabase._whenConstructed (package:drift/src/runtime/api/db_base.dart:73:12)
#2      new GeneratedDatabase (package:drift/src/runtime/api/db_base.dart:64:5)
#3      new _$Handle (package:example/Drift/insert.g.dart:332:31)
#4      new Handle (package:example/Drift/insert.dart:66:14)
#5      a (package:example/Drift/main.dart:5:12)
#6      main (package:example/Drift/main.dart:10:3)
#7      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:296:19)
#8      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12) This warning will only appear on debug builds. Process finished with exit code 0

해결방법

database handle class를 코드에서 2번 이상 호출하지 않는다.

설명

이 문제는 에러는 아니고, 일종의 경고문이다.
대충 database를 조작하는 class를 2번 이상 호출하면 문제가 생길 수 있으니 이렇게 사용하지 말라고 알려주는 것이다.

경고 메세지를 보지 않으려면 다음과 같은 방식으로 고쳐쓰면 된다.
database를 조작하는 class를 1번만 호출하기 때문에 경고 메세지를 노출하지 않는다.

import 'package:example/Drift/insert.dart';

void a(Database db){
  do_somthing;
}
void main() async {
  var db = await Handle();
  a(db);
  a(db);
}

drift 사용 방법

패키지 사용방법은 다음 페이지들을 확인하자

drift upsert 사용 예제

drift insert, update 사용 예제


공감 : 0







white.seolpyo.com