Skip to content

Commit

Permalink
let frb handles panic
Browse files Browse the repository at this point in the history
  • Loading branch information
dikatok committed Aug 24, 2024
1 parent bf57241 commit d44c2bc
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 777 deletions.
29 changes: 4 additions & 25 deletions lib/src/libsql_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,13 @@ class LibsqlClient {
openFlags: openFlags,
),
);
if (res.errorMessage?.isNotEmpty ?? false) {
throw Exception(res.errorMessage);
}
_connection = res.connection;
}

// Sync the embedded replica
Future<void> sync() async {
if (_connection == null) throw Exception('Database is not connected');
final res = await _connection!.sync_();
if (res.errorMessage?.isNotEmpty ?? false) {
throw Exception(res.errorMessage);
}
await _connection!.sync_();
}

/// Query the database, you can provide either named or positional parameters
Expand All @@ -120,9 +114,6 @@ class LibsqlClient {
positional: positional?.map(toLibsqlValue).toList(),
),
);
if (res.errorMessage?.isNotEmpty ?? false) {
throw Exception(res.errorMessage);
}
return res.rows
.map(
(row) => Map.fromEntries(
Expand Down Expand Up @@ -165,9 +156,6 @@ class LibsqlClient {
positional: positional?.map(toLibsqlValue).toList(),
),
);
if (res.errorMessage?.isNotEmpty ?? false) {
throw Exception(res.errorMessage);
}
return res.rowsAffected.toInt();
}

Expand All @@ -183,10 +171,7 @@ class LibsqlClient {
final res = await _connection!.prepare(
sql: sql,
);
if (res.errorMessage?.isNotEmpty ?? false) {
throw Exception(res.errorMessage);
}
return Statement(res.statement!);
return Statement(res.statement);
}

/// Run a batch transaction
Expand All @@ -195,19 +180,13 @@ class LibsqlClient {
/// * `sql` - batch SQL query, each statement is separated by a semicolon
Future<void> batch(String sql) async {
if (_connection == null) throw Exception('Database is not connected');
final res = await _connection!.batch(sql: sql);
if (res.errorMessage?.isNotEmpty ?? false) {
throw Exception(res.errorMessage);
}
await _connection!.batch(sql: sql);
}

Future<Transaction> transaction({LibsqlTransactionBehavior? behavior}) async {
if (_connection == null) throw Exception('Database is not connected');
final res = await _connection!.transaction(behavior: behavior);
if (res.errorMessage?.isNotEmpty ?? false) {
throw Exception(res.errorMessage);
}
return Transaction(res.transaction!);
return Transaction(res.transaction);
}

/// Close the database
Expand Down
Loading

0 comments on commit d44c2bc

Please sign in to comment.