Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions bin/libsqlite3_turso.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import 'dart:io';

import '../lib/database.dart';
import 'package:path/path.dart' as path;
import 'package:drift/drift.dart';

// ignore: public_member_api_docs
void copyBinaryIfNecessary() {
const libraryName = 'libsqlite3.so';
final systemBinary = File('/lib/$libraryName')..createSync(recursive: true);

final customBinary = () {
file({required bool debug}) => File(path.join(Directory.current.path,
'target', debug ? 'debug' : 'release', libraryName));

if (file(debug: false).existsSync()) {
return file(debug: false);
} else if (file(debug: true).existsSync()) {
return file(debug: true);
} else {
throw Exception('No custom SQLite binary found in target directory.');
}
}();

customBinary.copySync(systemBinary.path);
}

void main() async {
copyBinaryIfNecessary();

final database = AppDatabase();

await database.transaction(() async {
// Create the table if it doesn't exist
final result = await database.into(database.todoItems).insert(
TodoItemsCompanion.insert(
title: 'todo: setup drift',
content: 'We need to set up drift for our SQLite database.',
),
);

await (database
.update(database.todoItems)
..where((tbl) => tbl.id.equals(result)))
.write(TodoItemsCompanion(content: const Value('Updated content')));


print('Inserted item with ID: $result');
});

// final allItems = await database.select(database.todoItems).get();
// for (final item in allItems) {
// print('Item: ${item.title}, Content: ${item.content}');
// }

// final server = await HttpServer.bind(InternetAddress.anyIPv4, 8081);

// var index = 0;

// server.listen((request) async {
// final isEven = index % 2 == 0;

// final stopwatch = Stopwatch()..start();

// final result = await Future.wait([
// db.getAll('SELECT * FROM notes WHERE is_deleted = 0'),
// db.getAll(
// 'SELECT * FROM notes WHERE id = ?',
// ['8703e588-c847-4cb6-b250-726db8afb49a'],
// ),
// ]);
// stopwatch.stop();

// print('Query took ${stopwatch.elapsedMilliseconds} ms');

// request.response
// ..statusCode = HttpStatus.ok
// ..headers.contentType = ContentType.json
// ..write(isEven ? result[0] : result[1])
// ..close();

// index++;
// });

// print('Server running on http://${server.address.address}:${server.port}');
// ProcessSignal.sigterm.watch().listen((_) async {
// await server.close();
// await db.close();
// print('Server stopped.');
// });
}
44 changes: 0 additions & 44 deletions bin/proxy_server.dart

This file was deleted.

50 changes: 0 additions & 50 deletions bin/sqlite_test.dart

This file was deleted.

24 changes: 24 additions & 0 deletions lib/database.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:drift/drift.dart';
import 'package:drift/native.dart';
import 'package:sqlite3/sqlite3.dart';

part 'database.g.dart';

class TodoItems extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get title => text().withLength(min: 6, max: 32)();
TextColumn get content => text().named('body')();
DateTimeColumn get createdAt => dateTime().nullable()();
}

@DriftDatabase(tables: [TodoItems])
class AppDatabase extends _$AppDatabase {
AppDatabase() : super(_openConnection());

@override
int get schemaVersion => 1;

static QueryExecutor _openConnection() {
return NativeDatabase.opened(sqlite3.open('simple-nubian.db'));
}
}
Loading