Skip to content

Attaching two databases? #1151

Answered by davidmartos96
alexiswbr asked this question in Q&A
Apr 21, 2021 · 1 comments · 6 replies
Discussion options

You must be logged in to vote

@alexiswbr I had the requirement of attaching long ago and I solved it with the following.
Moor creates the tables for you when you define the DataClasses or moor files in your app, so what I did is make moor ignore the creation of the entities that belong to the attached database.
So instead of doing migrator.createAll() I have the following method, which is equivalent:

const Set<Type> kSchemaEntitiesToIgnore = {
  AttachedDbTable1,
  AttachedDbTable2,
};

Future<void> createAllSchemaEntities(Migrator m) async {
    for (final entity in allSchemaEntities) {
      if (kSchemaEntitiesToIgnore.contains(entity.runtimeType)) {
          continue;
      }

      if (entity is TableInfo) {
    …

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@davidmartos96
Comment options

@davidmartos96
Comment options

@alexiswbr
Comment options

@davidmartos96
Comment options

@alexiswbr
Comment options

Answer selected by alexiswbr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants