Using drift without flutter #3028
Replies: 3 comments 3 replies
-
That's awesome, I'm always excited to see Dart being used outside of Flutter! Drift was designed to support a pure Dart environment, but admittedly the "getting started" docs are kinds of Flutter-centric since that's realistically what almost all users need. |
Beta Was this translation helpful? Give feedback.
-
This is my import 'dart:ffi';
import 'dart:io';
import 'package:path/path.dart';
import 'package:sqlite3/open.dart';
import 'package:sqlite3/sqlite3.dart';
void main() async {
open.overrideFor(OperatingSystem.windows, _openOnWindows);
final db = sqlite3.openInMemory();
db.dispose();
}
DynamicLibrary _openOnWindows() {
final scriptDir = File(Platform.script.toFilePath()).parent;
final libraryNextToScript = File(join(scriptDir.path, 'sqlite3.dll'));
return DynamicLibrary.open(libraryNextToScript.path);
} And this is my import 'dart:ffi';
import 'dart:io';
import 'package:drift/drift.dart';
import 'package:sqlite3/open.dart';
import 'package:sqlite3/sqlite3.dart';
part 'db.g.dart';
class MailOverview extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get subject => text().withLength(min: 1, max: 255)();
TextColumn get sender => text().withLength(min: 1, max: 255)();
DateTimeColumn get date => dateTime()();
}
@DriftDatabase(tables: [MailOverview])
class AppDatabase extends _$AppDatabase {
AppDatabase() : super(_openConnection());
@override
int get schemaVersion => 1;
}
LazyDatabase _openConnection() {
return LazyDatabase(() async {
final dbFolder = new Directory('mails');
final file = File('${dbFolder.path}/db.sqlite');
return NativeDatabase.createInBackground(file);
});
} I am getting error with NativeDatabase class, its recognizing this class, what should I do?? |
Beta Was this translation helpful? Give feedback.
-
I am somewhat unclear about the sqlite3.so or .dll file. I don't have that much experience with sqlite. Can you tell me where to find this file and how to configure it for all the devices i.e. android, linux, windows etc. Also, why is it necessary to override and use a custom sqlite3.so file. |
Beta Was this translation helpful? Give feedback.
-
Hello everyone. I am using drift in my backend project in dart without flutter. But, it's someway using flutter libraries, and when I run my dart code, it gives errors. Can you please tell me how to use drift in dart without flutter.
Beta Was this translation helpful? Give feedback.
All reactions