surrealdb / surrealdb.net

SurrealDB SDK for .NET
https://surrealdb.com
Apache License 2.0
86 stars 16 forks source link

String incorrectly interpreted as record in Schemafull table #96

Open J05HM0N5TER opened 5 months ago

J05HM0N5TER commented 5 months ago

I have a scemafull with a field defined as string and if I set it to a string which is in the form of a record (e.g. test:string) then it throws an exception. There is a workaround in surrealql, but I don't know how to do that in this SDK.

Minimal replication example:

using SurrealDb.Net;
using SurrealDb.Net.Models.Auth;

public class Test {
    public required string Name { get; set; }
}

var db = new SurrealDbClient("ws://127.0.0.1:8000/rpc");
await db.SignIn(new RootAuth { Username = "root", Password = "root" });
await db.Use("test", "test");

const string tableName = "test";

await db.RawQuery(@$"DEFINE TABLE {tableName} SCHEMAFULL;
DEFINE FIELD name ON TABLE {tableName} TYPE string;");

await db.Create<Test>(tableName, new Test(){Name = "Test normal data"});
await db.Create<Test>(tableName, new Test(){Name = "Test normal data2"});
await db.Create<Test>(tableName, new Test(){Name = "Test normal data3"});
await db.Create<Test>(tableName, new Test(){Name = "example:string"});

Where it throws Error: SurrealDb.Net.Exceptions.SurrealDbException: There was a problem with the database: Found example:string for field `name`, with record `test:djqxpvplqi7eorq6pp9t`, but expected a string

As a workaround, I can set the type to be any, but that is no longer representative of the data I am putting in it.

Odonno commented 5 months ago

Hello Josh,

Unfortunately, the only solution for this to work is to write the Query by hand. This bug will be fixed in the future.

J05HM0N5TER commented 5 months ago

Hello Josh,

Unfortunately, the only solution for this to work is to write the Query by hand. This bug will be fixed in the future.

Thanks for the quick reply.

I am just planning on using any for now, since it works with my existing code and I think I can change it later if I need to.