Skip to content

Commit 0961076

Browse files
committed
add dart test files
1 parent c7c9bcd commit 0961076

File tree

3 files changed

+78
-62
lines changed

3 files changed

+78
-62
lines changed

bin/proxy_server.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import 'dart:convert';
2+
import 'dart:io';
3+
4+
void main() async {
5+
final server = await HttpServer.bind(InternetAddress.anyIPv4, 8080);
6+
7+
server.listen((request) async {
8+
if (request.uri.path == '/db/auth') {
9+
final response = {
10+
'db_url': 'staging-db-lhr-08c0519209-simple-tail-globe.turso.io',
11+
'db_token':
12+
'eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJhIjoicnciLCJleHAiOjE3NTQ2NzIwMDAsImlhdCI6MTc1NDU4NTYwMCwiaWQiOiJiMTZkZDkxMS05NmE4LTQzYTMtYTg3OC01ZGMzZjQ5MjVlZTkifQ.GrjdkI7SSLG3yTjpqFVzDGOdxs0PNlsvh3sVmkiQ-k0Rkvhv1h_-56tNmHLk_TYruW6vySmpr8UMhbKDN9tdBw',
13+
};
14+
15+
request.response
16+
..statusCode = HttpStatus.ok
17+
..headers.contentType = ContentType.json
18+
..write(json.encode(response))
19+
..close();
20+
return;
21+
}
22+
23+
// Handle the request
24+
if (request.method == 'GET') {
25+
request.response
26+
..write('Hello from the proxy server!')
27+
..close();
28+
} else {
29+
request.response
30+
..statusCode = HttpStatus.methodNotAllowed
31+
..write('Method not allowed')
32+
..close();
33+
}
34+
});
35+
36+
print(
37+
'Proxy server running on http://${server.address.address}:${server.port}');
38+
39+
// Handle server shutdown gracefully
40+
ProcessSignal.sigterm.watch().listen((_) async {
41+
await server.close();
42+
print('Proxy server stopped.');
43+
});
44+
}

bin/sqlite_test.dart

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import 'dart:io';
22

3-
import 'package:sqlite3/sqlite3.dart';
3+
import 'package:sqlite_async/sqlite_async.dart';
44
import 'package:path/path.dart' as path;
55

6+
final migrations = SqliteMigrations()
7+
..add(SqliteMigration(1, (tx) async {
8+
await tx.execute(
9+
'CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)',
10+
);
11+
}));
12+
613
// ignore: public_member_api_docs
714
void copyBinaryIfNecessary() {
815
const libraryName = 'libsqlite3.so';
@@ -13,24 +20,31 @@ void copyBinaryIfNecessary() {
1320
customBinary.copySync(systemBinary.path);
1421
}
1522

16-
void main() {
23+
void main() async {
1724
copyBinaryIfNecessary();
18-
19-
const commmands = [
20-
'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)',
21-
// "INSERT INTO users (name, email) VALUES ('Alice', '[email protected]')",
22-
];
23-
24-
final db = sqlite3.open('untrue-necklace');
25-
for (final command in commmands) db.execute(command);
26-
27-
// fetch data
28-
final result = db.select("SELECT * FROM users");
29-
for (final row in result) {
30-
stdout.writeln(
31-
'Artist[id: ${row['id']}, name: ${row['name']}, email: ${row['email']}]',
32-
);
33-
}
34-
35-
db.dispose();
25+
final db = SqliteDatabase(path: 'simple-nubian');
26+
27+
await migrations.migrate(db);
28+
29+
// // Use execute() or executeBatch() for INSERT/UPDATE/DELETE statements
30+
// await db.executeBatch('INSERT INTO users(name, email) values(?, ?)', [
31+
// ['Amen', '[email protected]'],
32+
// ['Moron', '[email protected]']
33+
// ]);
34+
35+
// var results = await db.getAll('SELECT * FROM users');
36+
// print('Results: $results');
37+
38+
// await db.writeTransaction((tx) async {
39+
// await tx.execute(
40+
// 'INSERT INTO users(name, email) values(?, ?)',
41+
// ['Test3', '[email protected]'],
42+
// );
43+
// await tx.execute(
44+
// 'INSERT INTO users(name, email) values(?, ?)',
45+
// ['Test4', '[email protected]'],
46+
// );
47+
// });
48+
49+
// await db.close();
3650
}

bin/sqlite_tnx_test.dart

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)