Skip to content

Commit edae93b

Browse files
committed
feat: completed all features except and , updated readme
1 parent 29da4a7 commit edae93b

File tree

6 files changed

+73
-60
lines changed

6 files changed

+73
-60
lines changed

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,20 @@ flutter pub get
4646
- <input type="checkbox" checked disabled /> [x] `select()`
4747
- <input type="checkbox" checked disabled /> [x] `query()`
4848
- <input type="checkbox" checked disabled /> [x] `transaction()`
49-
- <input type="checkbox" disabled /> [ ] `set()`
50-
- <input type="checkbox" disabled /> [ ] `unset()`
51-
- <input type="checkbox" disabled /> [ ] `signup()`
52-
- <input type="checkbox" disabled /> [ ] `signin()`
49+
- <input type="checkbox" checked disabled /> [x] `set()`
50+
- <input type="checkbox" checked disabled /> [x] `unset()`
51+
- <input type="checkbox" checked disabled /> [x] `signup()`
52+
- <input type="checkbox" checked disabled /> [x] `signin()`
5353
- <input type="checkbox" disabled /> [ ] `invalidate()`
5454
- <input type="checkbox" disabled /> [ ] `authenticate()`
55-
- <input type="checkbox" disabled /> [ ] `patch()`
56-
- <input type="checkbox" disabled /> [ ] `version()`
57-
- <input type="checkbox" disabled /> [ ] `health()`
55+
- <input type="checkbox" checked disabled /> [x] `patch()`
56+
- <input type="checkbox" checked disabled /> [x] `version()`
57+
- <input type="checkbox" checked disabled /> [x] `health()`
5858

5959
## 🏃 Examples
6060

61+
### Basic
62+
6163
```dart
6264
final db = Surreal();
6365
@@ -90,6 +92,22 @@ final deleted = await db.delete(created['id']);
9092

9193
For more code examples, kindly refer to the [integration test](https://github.com/limcheekin/surrealdb_wasm/blob/main/integration_test/surrealdb_wasm_test.dart) and the [example project](https://github.com/limcheekin/surrealdb_wasm/blob/main/example/lib/main.dart).
9294

95+
### Transaction Support
96+
97+
```dart
98+
final result = await db.transaction((txn) async {
99+
txn.query('DEFINE TABLE test SCHEMAFULL;');
100+
txn.query('DEFINE FIELD id ON test TYPE record;');
101+
txn.query('DEFINE FIELD name ON test TYPE string;');
102+
txn.query(
103+
r'CREATE test SET name = $name;',
104+
bindings: {'name': 'John'},
105+
);
106+
});
107+
```
108+
109+
For more code examples, kindly refer to the [integration test of transaction](https://github.com/limcheekin/surrealdb_wasm/blob/main/integration_test/transaction_test.dart).
110+
93111
## 🧑‍💼 Contributing
94112

95113
Contributions are welcome! Please check out the unimplemented features above, issues on the repository, and feel free to open a pull request.

assets/wasm/surrealdb/surrealdb.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,20 @@ import * as fflate from "https://cdn.skypack.dev/[email protected]?min";
2222
})();
2323

2424
class SurrealWrapper {
25-
2625
async set(key, value) {
27-
await this.db.set(key, value);
26+
await this.db.set(key, JSON.parse(value));
2827
}
2928

3029
async unset(key) {
3130
await this.db.unset(key);
3231
}
3332

3433
async signup(credentials) {
35-
return await this.db.signup(credentials);
34+
return await this.db.signup(JSON.parse(credentials));
3635
}
3736

3837
async signin(credentials) {
39-
return await this.db.signin(credentials);
38+
return await this.db.signin(JSON.parse(credentials));
4039
}
4140

4241
async invalidate() {
@@ -48,7 +47,7 @@ class SurrealWrapper {
4847
}
4948

5049
async patch(resource, data) {
51-
return await this.db.patch(resource, data);
50+
return await this.db.patch(resource, JSON.parse(data));
5251
}
5352

5453
async version() {

assets/wasm/surrealdb/surrealdb_wasm.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,21 +1868,20 @@ import * as fflate from "https://cdn.skypack.dev/[email protected]?min";
18681868
})();
18691869

18701870
class SurrealWrapper {
1871-
18721871
async set(key, value) {
1873-
await this.db.set(key, value);
1872+
await this.db.set(key, JSON.parse(value));
18741873
}
18751874

18761875
async unset(key) {
18771876
await this.db.unset(key);
18781877
}
18791878

18801879
async signup(credentials) {
1881-
return await this.db.signup(credentials);
1880+
return await this.db.signup(JSON.parse(credentials));
18821881
}
18831882

18841883
async signin(credentials) {
1885-
return await this.db.signin(credentials);
1884+
return await this.db.signin(JSON.parse(credentials));
18861885
}
18871886

18881887
async invalidate() {
@@ -1894,7 +1893,7 @@ class SurrealWrapper {
18941893
}
18951894

18961895
async patch(resource, data) {
1897-
return await this.db.patch(resource, data);
1896+
return await this.db.patch(resource, JSON.parse(data));
18981897
}
18991898

19001899
async version() {

assets/wasm/surrealdb/surrealdb_wasm.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
7 Bytes
Binary file not shown.

integration_test/surrealdb_wasm_test.dart

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,31 @@ DEFINE FIELD created ON document TYPE datetime;
168168
final result = await db.select(id);
169169
expect(result, isNull);
170170
});
171-
// Integration tests for set method
172-
testWidgets('set method test', (WidgetTester tester) async {
171+
172+
testWidgets('set test', (WidgetTester tester) async {
173173
await db.set('testKey', 'testValue');
174174
});
175175

176-
// Integration tests for unset method
177-
testWidgets('unset method test', (WidgetTester tester) async {
176+
testWidgets('unset test', (WidgetTester tester) async {
178177
await db.set('testKey', 'testValue');
179178
await db.unset('testKey');
180179
});
181180

182-
// Integration tests for signup method
183-
testWidgets('signup method test', (WidgetTester tester) async {
181+
testWidgets('patch test', (WidgetTester tester) async {
182+
await db.create('keyValue', {'key': 'value'});
183+
await db.patch('keyValue', [
184+
{'op': 'replace', 'path': '/key', 'value': 'newValue'},
185+
]);
186+
final result = await db.query('SELECT key FROM keyValue');
187+
expect(
188+
result,
189+
equals([
190+
{'key': 'newValue'},
191+
]),
192+
);
193+
});
194+
195+
testWidgets('signup test', (WidgetTester tester) async {
184196
await db.query(defineScopeStatement);
185197
final credentials = {
186198
'namespace': 'surreal',
@@ -190,59 +202,44 @@ DEFINE FIELD created ON document TYPE datetime;
190202
'password': 'password123',
191203
};
192204
final result = await db.signup(credentials);
193-
print('signup $result');
194205
expect(result, isNotNull);
195206
});
196207

197-
// Integration tests for signin method
198-
testWidgets('signin method test', (WidgetTester tester) async {
199-
final credentials = {'user': 'testUser', 'pass': 'testPass'};
208+
testWidgets('signin test', (WidgetTester tester) async {
209+
final credentials = {
210+
'namespace': 'surreal',
211+
'database': 'surreal',
212+
'scope': 'user_scope',
213+
'email': '[email protected]',
214+
'password': 'password456',
215+
};
200216
await db.signup(credentials);
201217
final result = (await db.signin(credentials))! as String;
202-
expect(result, contains('token'));
218+
expect(result, isNotNull);
203219
});
204220

205-
// Integration tests for invalidate method
206-
testWidgets('invalidate method test', (WidgetTester tester) async {
207-
final credentials = {'user': 'testUser', 'pass': 'testPass'};
221+
/* FAILED???
222+
testWidgets('authenticate and invalidate test', (WidgetTester tester) async {
223+
final credentials = {
224+
'namespace': 'surreal',
225+
'database': 'surreal',
226+
'scope': 'user_scope',
227+
'email': '[email protected]',
228+
'password': 'password789',
229+
};
208230
await db.signup(credentials);
209231
final token = (await db.signin(credentials))! as String;
210232
await db.authenticate(token);
211233
await db.invalidate();
212-
final result = await db.query('INFO FOR USER');
213-
expect(result, isNull);
214-
});
215-
216-
// Integration tests for authenticate method
217-
testWidgets('authenticate method test', (WidgetTester tester) async {
218-
final credentials = {'user': 'testUser', 'pass': 'testPass'};
219-
await db.signup(credentials);
220-
final token = (await db.signin(credentials))! as String;
221-
await db.authenticate(token);
222-
final result = await db.query('INFO FOR USER');
223-
expect(result, isNotNull);
224-
});
225-
226-
// Integration tests for patch method
227-
testWidgets('patch method test', (WidgetTester tester) async {
228-
await db.create('keyValue', {'key': 'value'});
229-
await db.patch('keyValue', [
230-
{'op': 'replace', 'path': '/key', 'value': 'newValue'},
231-
]);
232-
final result = await db.query('SELECT key FROM keyValue');
233-
expect(result, equals('newValue'));
234234
});
235+
*/
235236

236-
// Integration tests for version method
237-
testWidgets('version method test', (WidgetTester tester) async {
237+
testWidgets('version test', (WidgetTester tester) async {
238238
final result = await db.version();
239239
expect(result, isNotNull);
240240
});
241241

242-
// Integration tests for health method
243-
testWidgets('health method test', (WidgetTester tester) async {
242+
testWidgets('health test', (WidgetTester tester) async {
244243
await db.health();
245-
// Assuming health check passes if no exception is thrown
246-
expect(true, isTrue);
247244
});
248245
}

0 commit comments

Comments
 (0)