drift icon indicating copy to clipboard operation
drift copied to clipboard

More memory/temporary table support

Open glanium opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. Drift now supports in-memory/temporary DB but as standalone DB. I need to use in-memory/temporary DB as second DB(attached DB).

Describe the solution you'd like One possible way for it is

Add option to disable auto table creation for in-memory/temporary table and option to specify schema for Table

@DisaleAutoCreate   
class InMemoryDbTable extends Table (
  
  @override
  String get schema = 'aux1';    // or   schema() method like alias()
)

  @override
  int get schemaVersion => 1;

  @override
  MigrationStrategy get migration {
    return MigrationStrategy(beforeOpen: (details) async {
      await customStatement('ATTACH DATABASE ':memory:' AS aux1');   // attach to memory DB
      InMemoryDbTable.createTable();  // manually create table
    });
  }

SQLite In-Memory Databases

thx.

glanium avatar Sep 20 '23 12:09 glanium

Related to #1366 and #1159.

I agree that we should support something like this, but we need a clear way to separate the different schemas. Maybe this could also be a part of the database annotation:

@DriftDatabase(
  tables: [Users],
  additionalSchemas: {
    'aux1': [InMemoryDbTable]
  },
)

simolus3 avatar Sep 21 '23 20:09 simolus3