Skip to content

Commit 7d53e22

Browse files
committed
feat: ready for 0.9.0+6 released.
1 parent 5d6377f commit 7d53e22

File tree

5 files changed

+67
-25
lines changed

5 files changed

+67
-25
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ Changes to the project are tracked using build numbers behind the version number
1111

1212
## [Unreleased]
1313

14+
## [0.9.0+6] - 2024-03-13
15+
16+
- Feat: Upgraded to surrealdb.wasm 0.9.0, the official release of wasm module of the surrealdb 1.3.0.
17+
- Feat: API breaking changes:
18+
- `db.select()` and `db.query()` that return single result, no longer requiring casting to `List` and retrieval by `.first`.
19+
- Fix: Catched the error `Encountered a non-object value in array` within the library, preventing it from being exposed to the user. Reported the bug at [surrealdb.wasm#56](https://github.com/surrealdb/surrealdb.wasm/issues/56).
20+
1421

1522
## [0.8.0+5] - 2024-03-07
1623

17-
- Upgraded to official surrealdb.wasm 0.8.0 released for surrealdb 1.2.0.
24+
- Upgraded to the official surrealdb.wasm 0.8.0 released for surrealdb 1.2.0.
1825
- API breaking changes:
1926
- Previous: `db.use(ns: 'test', db: 'test');`
2027
- Current: `db.use(namespace: 'test', database: 'test');`

RELEASE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- Upgraded to official surrealdb.wasm 0.8.0 released for surrealdb 1.2.0.
2-
- API breaking changes:
3-
- Previous: `db.use(ns: 'test', db: 'test');`
4-
- Current: `db.use(namespace: 'test', database: 'test');`
1+
- Feat: Upgraded to surrealdb.wasm 0.9.0, the official release of wasm module of the surrealdb 1.3.0.
2+
- Feat: API breaking changes:
3+
- `db.select()` and `db.query()` that return single result, no longer requiring casting to `List` and retrieval by `.first`.
4+
- Fix: Catched the error `Encountered a non-object value in array` within the library, preventing it from being exposed to the user. Reported the bug at [surrealdb.wasm#56](https://github.com/surrealdb/surrealdb.wasm/issues/56).

integration_test/transaction_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void main() {
111111
txn.query('');
112112
});
113113

114-
expect(result, isEmpty);
114+
expect(result, isNull);
115115
});
116116

117117
test('Concurrent Transactions: Multiple transactions execute concurrently',

lib/src/surrealdb_wasm.dart

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class Surreal {
264264
data is Map || data is Iterable ? jsonEncode(data) : data,
265265
),
266266
);
267-
return (dartify(result)! as List).first;
267+
return _wrap(result);
268268
}
269269

270270
/// Updates a specific resource(record)
@@ -309,7 +309,7 @@ class Surreal {
309309
data is Map || data is Iterable ? jsonEncode(data) : data,
310310
),
311311
);
312-
return (dartify(result)! as List).first;
312+
return _wrap(result);
313313
}
314314

315315
/// Merges data into an existing resource(record) or resources(records).
@@ -341,7 +341,7 @@ class Surreal {
341341
data is Map || data is Iterable ? jsonEncode(data) : data,
342342
),
343343
);
344-
return (dartify(result)! as List).first;
344+
return _wrap(result);
345345
}
346346

347347
/// Selects and retrieves all resources(records)
@@ -361,16 +361,17 @@ class Surreal {
361361
/// final person = await db.select('person:h5wxrf2ewk8xjxosxtyc');
362362
/// ```
363363
Future<Object?> select(String resource) async {
364-
print('** select resource $resource');
365-
final result = await promiseToFuture<Object?>(
366-
_surreal.select(
367-
resource,
368-
),
364+
return _handleError(
365+
resource,
366+
(resource) async {
367+
final result = await promiseToFuture<Object?>(
368+
_surreal.select(
369+
resource,
370+
),
371+
);
372+
return _wrap(result);
373+
},
369374
);
370-
print('** select result $result');
371-
final list = dartify(result)! as List;
372-
print('** select list $list');
373-
return list.isEmpty ? null : (list.length == 1 ? list.first : list);
374375
}
375376

376377
/// Executes a SurrealQL query on the database.
@@ -398,8 +399,7 @@ class Surreal {
398399
jsonEncode(bindings),
399400
),
400401
);
401-
final list = dartify(result)! as List;
402-
return list.isNotEmpty ? list.first : list;
402+
return _wrap(result);
403403
}
404404

405405
/// Deletes a specific resource(record) or all resources(records).
@@ -418,11 +418,46 @@ class Surreal {
418418
/// final record = await db.delete('person:h5wxrf2ewk8xjxosxtyc');
419419
/// ```
420420
Future<Object?> delete(String resource) async {
421-
final result = await promiseToFuture<Object?>(
422-
_surreal.delete(
423-
resource,
424-
),
421+
return _handleError(
422+
resource,
423+
(resource) async {
424+
final result = await promiseToFuture<Object?>(
425+
_surreal.delete(
426+
resource,
427+
),
428+
);
429+
return _wrap(result);
430+
},
425431
);
432+
}
433+
434+
Future<Object?> _handleError(
435+
String resource,
436+
Future<Object?> Function(
437+
String resource,
438+
) sqlFunction,
439+
) async {
440+
try {
441+
return await sqlFunction(resource);
442+
} catch (e) {
443+
// Catch the error.
444+
if (e is String &&
445+
e.contains('Encountered a non-object value in array')) {
446+
// If it's the specific error we're looking for,
447+
// not handled due to the reported issue.
448+
print('''
449+
ERROR: "$e" is not handled.
450+
Please see https://github.com/surrealdb/surrealdb.wasm/issues/56.''');
451+
return null;
452+
} else {
453+
// If it's any other error, rethrow it.
454+
rethrow;
455+
}
456+
}
457+
}
458+
459+
Object? _wrap(Object? result) {
460+
if (result == null || dartify(result) == null) return null;
426461
final list = dartify(result)! as List;
427462
return list.isEmpty ? null : (list.length == 1 ? list.first : list);
428463
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: surrealdb_wasm
22
description: Flutter SurrealDB WebAssembly(WASM) package
3-
version: 0.8.0
3+
version: 0.9.0
44
repository: https://github.com/limcheekin/surrealdb_wasm
55

66
environment:

0 commit comments

Comments
 (0)