Skip to content

Commit

Permalink
✅ update surrealdb dependency to 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Odonno committed Sep 21, 2023
1 parent dc55095 commit c1d6286
Show file tree
Hide file tree
Showing 23 changed files with 76 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
run: curl --proto '=https' --tlsv1.2 -sSf https://install.surrealdb.com | sh

- name: Run SurrealDB root
run: surreal start --user root --pass root memory &
run: surreal start --user root --pass root memory --auth --allow-guests &

- name: Setup dotnet 6.0
uses: actions/setup-dotnet@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
run: curl --proto '=https' --tlsv1.2 -sSf https://install.surrealdb.com | sh

- name: Run SurrealDB root
run: surreal start --user root --pass root memory &
run: surreal start --user root --pass root memory --auth --allow-guests &

- name: Setup dotnet 6.0
uses: actions/setup-dotnet@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
run: curl --proto '=https' --tlsv1.2 -sSf https://install.surrealdb.com | sh

- name: Run SurrealDB root
run: surreal start --user root --pass root memory &
run: surreal start --user root --pass root memory --auth --allow-guests &

- name: Setup dotnet 6.0
uses: actions/setup-dotnet@v3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ Unit/Integration tests are written using [xUnit](https://xunit.net/) and [Fluent
You will need a local SurrealDB instance alongside the tests. Start one using the following command:

```
surreal start --log debug --user root --pass root memory
surreal start --log debug --user root --pass root memory --auth --allow-guests
```

Once ready, go to the root directory of the project and run the following command:
Expand All @@ -275,7 +275,7 @@ This project also contains [benchmarks](https://benchmarkdotnet.org/) in order t
You will need a local SurrealDB instance alongside the tests. Start one using the following command:

```
surreal start --log debug --user root --pass root memory
surreal start --log debug --user root --pass root memory --auth --allow-guests
```

Once ready, go to the root directory of the project and run the following command:
Expand Down
7 changes: 6 additions & 1 deletion SurrealDb.Benchmarks/Models/Post.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using SurrealDb.Models;
using System.Text.Json.Serialization;

namespace SurrealDb.Benchmarks.Models;

public class Post : Record
{
public string? Title { get; set; }
public string? Content { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Status { get; set; }
public DateTime CreatedAt { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public DateTime? CreatedAt { get; set; }
}
22 changes: 11 additions & 11 deletions SurrealDb.Benchmarks/Schemas/ecommerce.surql
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ DEFINE TABLE address SCHEMALESS;
DEFINE FIELD number ON address TYPE string;
DEFINE FIELD street ON address TYPE string;
DEFINE FIELD city ON address TYPE string;
DEFINE FIELD state ON address TYPE string;
DEFINE FIELD zip_code ON address TYPE string;
DEFINE FIELD state ON address TYPE option<string>;
DEFINE FIELD zip_code ON address TYPE option<string>;
DEFINE FIELD country ON address TYPE string;

---------------------------------------------
DEFINE TABLE customer SCHEMALESS;

DEFINE FIELD name ON customer TYPE string;
DEFINE FIELD email ON customer TYPE string;
DEFINE FIELD address ON customer TYPE record(address);
DEFINE FIELD address ON customer TYPE record<address>;

---------------------------------------------
DEFINE TABLE product SCHEMALESS;
Expand All @@ -21,29 +21,29 @@ DEFINE FIELD name ON product TYPE string;
DEFINE FIELD description ON product TYPE string;
DEFINE FIELD price ON product TYPE number;
DEFINE FIELD category ON product TYPE string;
DEFINE FIELD images ON product TYPE array;
DEFINE FIELD images ON product TYPE array<string>;

---------------------------------------------
# in: customer
# out: product
DEFINE TABLE purchased SCHEMALESS;

DEFINE FIELD quantity ON purchased TYPE number;
DEFINE FIELD shipping_address ON purchased TYPE record(address);
DEFINE FIELD created_at ON purchased TYPE datetime VALUE $before OR time::now();
DEFINE FIELD shipped_at ON purchased TYPE datetime;
DEFINE FIELD shipping_address ON purchased TYPE option<record<address>>;
DEFINE FIELD created_at ON purchased TYPE datetime DEFAULT time::now();
DEFINE FIELD shipped_at ON purchased TYPE option<datetime>;
DEFINE FIELD total ON purchased TYPE number;
DEFINE FIELD status ON purchased TYPE string VALUE $value OR $before OR 'Pending' ASSERT $value == NONE OR $value INSIDE ['Pending', 'Delivered'];
DEFINE FIELD status ON purchased TYPE string DEFAULT 'Pending' ASSERT $value INSIDE ['Pending', 'Delivered'];

---------------------------------------------
DEFINE TABLE purchase SCHEMALESS;

DEFINE FIELD customer ON purchase TYPE record(customer);
DEFINE FIELD product ON purchase TYPE record(product);
DEFINE FIELD customer ON purchase TYPE record<customer>;
DEFINE FIELD product ON purchase TYPE record<product>;
DEFINE FIELD quantity ON purchase TYPE number;
DEFINE FIELD total ON purchase TYPE number;

DEFINE EVENT purchase ON TABLE purchase WHEN $before == NONE THEN {
DEFINE EVENT purchase ON TABLE purchase WHEN $event = "CREATE" THEN {
LET $from = (SELECT * FROM customer WHERE id == $after.customer);
LET $to = (SELECT * FROM product WHERE id == $after.product);

Expand Down
4 changes: 2 additions & 2 deletions SurrealDb.Benchmarks/Schemas/post.surql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ DEFINE TABLE post SCHEMAFULL;

DEFINE FIELD title ON post TYPE string;
DEFINE FIELD content ON post TYPE string;
DEFINE FIELD created_at ON post TYPE datetime VALUE $before OR time::now();
DEFINE FIELD status ON post TYPE string VALUE $value OR $before OR 'DRAFT' ASSERT $value == NONE OR $value INSIDE ['DRAFT', 'PUBLISHED'];
DEFINE FIELD created_at ON post TYPE datetime DEFAULT time::now();
DEFINE FIELD status ON post TYPE string DEFAULT 'DRAFT' ASSERT $value INSIDE ['DRAFT', 'PUBLISHED'];
36 changes: 6 additions & 30 deletions SurrealDb.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public async Task ShouldParseDecimal(string url)
{
var floatRecord = records.Find(r => r.Name == "float");
floatRecord.Should().NotBeNull();
floatRecord!.Value.Should().Be(13.571938471938473m);
floatRecord!.Value.Should().Be(13.571938471938472m);
}
}

Expand Down Expand Up @@ -432,7 +432,7 @@ public async Task ShouldParseDouble(string url)
{
var floatRecord = records.Find(r => r.Name == "float");
floatRecord.Should().NotBeNull();
floatRecord!.Value.Should().Be(13.571938471938473d);
floatRecord!.Value.Should().Be(13.571938471938472d);
}
}

Expand Down Expand Up @@ -481,13 +481,13 @@ public async Task ShouldParseDuration(string url)
{
var microsecondRecord = records.Find(r => r.Name == "microsecond");
microsecondRecord.Should().NotBeNull();
microsecondRecord!.Value.NanoSeconds.Should().Be(3000); // TODO : Fix this in SurrealDB
microsecondRecord!.Value.MicroSeconds.Should().Be(3);
}

{
var microsecondAliasRecord = records.Find(r => r.Name == "microsecond-alias");
microsecondAliasRecord.Should().NotBeNull();
microsecondAliasRecord!.Value.NanoSeconds.Should().Be(4000); // TODO : Fix this in SurrealDB
microsecondAliasRecord!.Value.MicroSeconds.Should().Be(4);
}

{
Expand Down Expand Up @@ -540,12 +540,6 @@ public async Task ShouldParseDuration(string url)
complexRecord!.Value.Minutes.Should().Be(30);
complexRecord!.Value.Hours.Should().Be(1);
}

{
var halfHourRecord = records.Find(r => r.Name == "decimal");
halfHourRecord.Should().NotBeNull();
halfHourRecord!.Value.Seconds.Should().Be(0);
}
}

[Theory]
Expand Down Expand Up @@ -640,12 +634,6 @@ public async Task ShouldParseDurationAsTimeSpan(string url)
complexRecord.Should().NotBeNull();
complexRecord!.Value.TotalSeconds.Should().Be(5421.35);
}

{
var halfHourRecord = records.Find(r => r.Name == "decimal");
halfHourRecord.Should().NotBeNull();
halfHourRecord!.Value.TotalSeconds.Should().Be(0);
}
}

[Theory]
Expand Down Expand Up @@ -684,13 +672,13 @@ public async Task ShouldParseDurationAsString(string url)
{
var microsecondRecord = records.Find(r => r.Name == "microsecond");
microsecondRecord.Should().NotBeNull();
microsecondRecord!.Value.Should().Be("3000ns");
microsecondRecord!.Value.Should().Be("3µs");
}

{
var microsecondAliasRecord = records.Find(r => r.Name == "microsecond-alias");
microsecondAliasRecord.Should().NotBeNull();
microsecondAliasRecord!.Value.Should().Be("4000ns");
microsecondAliasRecord!.Value.Should().Be("4µs");
}

{
Expand Down Expand Up @@ -740,12 +728,6 @@ public async Task ShouldParseDurationAsString(string url)
complexRecord.Should().NotBeNull();
complexRecord!.Value.Should().Be("1h30m21s350ms");
}

{
var halfHourRecord = records.Find(r => r.Name == "decimal");
halfHourRecord.Should().NotBeNull();
halfHourRecord!.Value.Should().Be("0ns");
}
}

[Theory]
Expand Down Expand Up @@ -840,12 +822,6 @@ public async Task ShouldParseTimeOnly(string url)
complexRecord.Should().NotBeNull();
complexRecord!.Value.Should().Be(new TimeOnly(01, 30, 21, 350));
}

{
var halfHourRecord = records.Find(r => r.Name == "decimal");
halfHourRecord.Should().NotBeNull();
halfHourRecord!.Value.Should().Be(new TimeOnly());
}
}

[Theory]
Expand Down
18 changes: 13 additions & 5 deletions SurrealDb.Tests/QueryTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SurrealDb.Exceptions;
using SurrealDb.Internals.Models;
using SurrealDb.Models.Response;
using System.Net;
using System.Reflection;
using System.Text;

namespace SurrealDb.Tests;
Expand Down Expand Up @@ -79,17 +79,21 @@ public async Task ShouldHaveOneProtocolErrorResult(string url)
await client.Query(query);
}
{
string query = "SELECT;";
string query = "abc def;";
response = await client.Query(query);
}
};

if (isWebsocket)
{
await func.Should().ThrowAsync<SurrealDbException>().WithMessage("There was a problem with the database: Parse error on line 1 at character 0 when parsing 'SELECT;'");
await func.Should().ThrowAsync<SurrealDbException>().WithMessage(@"There was a problem with the database: Parse error: Failed to parse query at line 1 column 5 expected query to end
|
1 | abc def;
| ^ perhaps missing a semicolon on the previous statement?
");
}
else
{
Expand All @@ -105,7 +109,11 @@ public async Task ShouldHaveOneProtocolErrorResult(string url)
errorResult!.Code.Should().Be(HttpStatusCode.BadRequest);
errorResult!.Details.Should().Be("Request problems detected");
errorResult!.Description.Should().Be("There is a problem with your request. Refer to the documentation for further information.");
errorResult!.Information.Should().Be("There was a problem with the database: Parse error on line 1 at character 0 when parsing 'SELECT;'");
errorResult!.Information.Should().Be(@"There was a problem with the database: Parse error: Failed to parse query at line 1 column 5 expected query to end
|
1 | abc def;
| ^ perhaps missing a semicolon on the previous statement?
");
}
}

Expand Down
2 changes: 1 addition & 1 deletion SurrealDb.Tests/Schemas/datetime.surql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DEFINE TABLE datetime SCHEMAFULL;

DEFINE FIELD name ON datetime TYPE string;
DEFINE FIELD value ON datetime TYPE datetime;
DEFINE FIELD value ON datetime TYPE option<datetime>;

CREATE datetime SET name = 'none', value = NONE;
CREATE datetime SET name = "time", value = "2022-07-03T07:18:52Z";
Expand Down
6 changes: 3 additions & 3 deletions SurrealDb.Tests/Schemas/decimal.surql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
DEFINE TABLE decimal SCHEMAFULL;

DEFINE FIELD name ON decimal TYPE string;
DEFINE FIELD value ON decimal TYPE number;
DEFINE FIELD value ON decimal TYPE option<number>;

CREATE decimal SET name = 'none', value = NONE;
CREATE decimal SET name = 'min', value = -9223372036854775808;
CREATE decimal SET name = 'max', value = 9223372036854775807;
CREATE decimal SET name = 'zero', value = 0;
CREATE decimal SET name = 'decimal', value = 41.5;
CREATE decimal SET name = 'decimal-precision', value = 13.5719384719384719385639856394139476937756394756;
CREATE decimal SET name = 'decimal', value = 41.5dec;
CREATE decimal SET name = 'decimal-precision', value = 13.5719384719384719385639856394139476937756394756dec;
CREATE decimal SET name = 'float', value = <float> 13.5719384719384719385639856394139476937756394756;
5 changes: 2 additions & 3 deletions SurrealDb.Tests/Schemas/duration.surql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DEFINE TABLE duration SCHEMAFULL;

DEFINE FIELD name ON duration TYPE string;
DEFINE FIELD value ON duration TYPE duration;
DEFINE FIELD value ON duration TYPE option<duration>;

CREATE duration SET name = 'none', value = NONE;
CREATE duration SET name = 'nanosecond', value = 2ns;
Expand All @@ -14,5 +14,4 @@ CREATE duration SET name = 'hour', value = 1h;
CREATE duration SET name = 'day', value = 6d;
CREATE duration SET name = 'week', value = 28w;
CREATE duration SET name = 'year', value = 12y;
CREATE duration SET name = 'complex', value = 1h30m20s1350ms;
CREATE duration SET name = 'decimal', value = '0.5h';
CREATE duration SET name = 'complex', value = 1h30m20s1350ms;
2 changes: 1 addition & 1 deletion SurrealDb.Tests/Schemas/number.surql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DEFINE TABLE number SCHEMAFULL;

DEFINE FIELD name ON number TYPE string;
DEFINE FIELD value ON number TYPE number;
DEFINE FIELD value ON number TYPE option<number>;

CREATE number SET name = 'none', value = NONE;
CREATE number SET name = 'min', value = -9223372036854775808;
Expand Down
4 changes: 2 additions & 2 deletions SurrealDb.Tests/Schemas/post.surql
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ DEFINE TABLE post SCHEMAFULL

DEFINE FIELD title ON post TYPE string;
DEFINE FIELD content ON post TYPE string;
DEFINE FIELD created_at ON post TYPE datetime VALUE $before OR time::now();
DEFINE FIELD status ON post TYPE string VALUE $value OR $before OR 'DRAFT' ASSERT $value == NONE OR $value INSIDE ['DRAFT', 'PUBLISHED'];
DEFINE FIELD created_at ON post TYPE datetime DEFAULT time::now();
DEFINE FIELD status ON post TYPE string DEFAULT 'DRAFT' ASSERT $value INSIDE ['DRAFT', 'PUBLISHED'];

CREATE post:first SET title = "First article", content = "This is my first article";
CREATE post SET title = "Second article", content = "Another article";
2 changes: 1 addition & 1 deletion SurrealDb.Tests/Schemas/string.surql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DEFINE TABLE string SCHEMAFULL;

DEFINE FIELD name ON string TYPE string;
DEFINE FIELD value ON string TYPE string;
DEFINE FIELD value ON string TYPE option<string>;

CREATE string SET name = 'none', value = NONE;
CREATE string SET name = 'single-quote', value = 'Lorem ipsum dolor sit amet';
Expand Down
8 changes: 4 additions & 4 deletions SurrealDb.Tests/Schemas/user.surql
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ DEFINE TABLE user SCHEMAFULL
FOR update WHERE id = $auth.id
FOR create, delete NONE;

DEFINE FIELD username ON user TYPE string ASSERT $value != NONE;
DEFINE FIELD email ON user TYPE string ASSERT is::email($value);
DEFINE FIELD password ON user TYPE string ASSERT $value != NONE;
DEFINE FIELD registered_at ON user TYPE datetime VALUE $before OR time::now();
DEFINE FIELD username ON user TYPE string;
DEFINE FIELD email ON user TYPE string ASSERT string::is::email($value);
DEFINE FIELD password ON user TYPE string;
DEFINE FIELD registered_at ON user TYPE datetime DEFAULT time::now();
DEFINE FIELD avatar ON user TYPE string;

DEFINE INDEX unique_username ON user COLUMNS username UNIQUE;
Expand Down
2 changes: 1 addition & 1 deletion SurrealDb.Tests/Schemas/vector.surql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DEFINE TABLE vector SCHEMAFULL;

DEFINE FIELD name ON vector TYPE string;
DEFINE FIELD value ON vector TYPE array;
DEFINE FIELD value ON vector TYPE option<array>;
DEFINE FIELD value.* ON vector TYPE number;

CREATE vector:none SET name = "none", value = NONE;
Expand Down
Loading

0 comments on commit c1d6286

Please sign in to comment.