Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/bindings-csharp/Codegen.Tests/fixtures/diag/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,9 @@ public partial class ViewPrimaryKeyPartialRow
[SpacetimeDB.Type]
public partial struct NonEquatableViewPrimaryKey
{

public uint Value;
public uint Extra;
}

[SpacetimeDB.Type]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions crates/bindings-csharp/Codegen.Tests/fixtures/server/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,25 @@ partial struct FormerlyForbiddenFieldNames
public uint GetAlgebraicType;
}

[SpacetimeDB.Type]
public partial struct ItemKey
{
public ulong Value;

public static implicit operator ulong(ItemKey key) => key.Value;

public static implicit operator ItemKey(ulong value) => new() { Value = value };
}

[SpacetimeDB.Table(Name = "item", Public = true)]
public partial struct Item
{
[SpacetimeDB.PrimaryKey]
public ItemKey Key;

public string Name;
}

public class Module
{
[SpacetimeDB.ClientVisibilityFilter]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ public readonly partial struct QueryBuilder
new("BTreeViews", new BTreeViewsCols("BTreeViews"), new BTreeViewsIxCols("BTreeViews"));
}

public readonly struct ItemCols
{
public readonly global::SpacetimeDB.Col<global::Item, ItemKey> Key;
public readonly global::SpacetimeDB.Col<global::Item, string> Name;

internal ItemCols(string tableName)
{
Key = new global::SpacetimeDB.Col<global::Item, ItemKey>(tableName, "Key");
Name = new global::SpacetimeDB.Col<global::Item, string>(tableName, "Name");
}
}

public readonly struct ItemIxCols
{
public readonly global::SpacetimeDB.IxCol<global::Item, ItemKey> Key;

internal ItemIxCols(string tableName)
{
Key = new global::SpacetimeDB.IxCol<global::Item, ItemKey>(tableName, "Key");
}
}

public readonly partial struct QueryBuilder
{
public global::SpacetimeDB.Table<global::Item, ItemCols, ItemIxCols> Item() =>
new("Item", new ItemCols("Item"), new ItemIxCols("Item"));
}

public readonly struct MultiTable1Cols
{
public readonly global::SpacetimeDB.Col<global::MultiTableRow, string> Name;
Expand Down Expand Up @@ -713,6 +741,7 @@ public sealed class Local : global::SpacetimeDB.LocalBase
internal global::SpacetimeDB.Internal.TableHandles.BTreeMultiColumn BTreeMultiColumn =>
new();
internal global::SpacetimeDB.Internal.TableHandles.BTreeViews BTreeViews => new();
public global::SpacetimeDB.Internal.TableHandles.Item Item => new();
public global::SpacetimeDB.Internal.TableHandles.MultiTable1 MultiTable1 => new();
public global::SpacetimeDB.Internal.TableHandles.MultiTable2 MultiTable2 => new();
public global::SpacetimeDB.Internal.TableHandles.PrivateTable PrivateTable => new();
Expand Down Expand Up @@ -1128,6 +1157,77 @@ public ulong Delete(global::SpacetimeDB.Bound<string> Faction) =>
internal FactionIndex Faction => new();
}

public readonly struct Item : global::SpacetimeDB.Internal.ITableView<Item, global::Item>
{
public static global::Item ReadGenFields(System.IO.BinaryReader reader, global::Item row)
{
return row;
}

public static SpacetimeDB.Internal.RawTableDefV10 MakeTableDesc(
SpacetimeDB.BSATN.ITypeRegistrar registrar
) =>
new(
SourceName: nameof(Item),
ProductTypeRef: (uint)new global::Item.BSATN().GetAlgebraicType(registrar).Ref_,
PrimaryKey: [0],
Indexes:
[
new(
SourceName: "Item_Key_idx_btree",
AccessorName: "Key",
Algorithm: new SpacetimeDB.Internal.RawIndexAlgorithm.BTree([0])
)
],
Constraints:
[
global::SpacetimeDB.Internal.ITableView<
Item,
global::Item
>.MakeUniqueConstraint(0)
],
Sequences: [],
TableType: SpacetimeDB.Internal.TableType.User,
TableAccess: SpacetimeDB.Internal.TableAccess.Public,
DefaultValues: [],
IsEvent: false
);

public static SpacetimeDB.Internal.RawScheduleDefV10? MakeScheduleDesc() => null;

/// <summary>
/// Returns the number of rows in this table.
///
/// This reads datastore metadata, so it runs in constant time.
/// It also takes into account modifications by the current transaction.
/// </summary>
public ulong Count => global::SpacetimeDB.Internal.ITableView<Item, global::Item>.DoCount();

public IEnumerable<global::Item> Iter() =>
global::SpacetimeDB.Internal.ITableView<Item, global::Item>.DoIter();

public global::Item Insert(global::Item row) =>
global::SpacetimeDB.Internal.ITableView<Item, global::Item>.DoInsert(row);

public bool Delete(global::Item row) =>
global::SpacetimeDB.Internal.ITableView<Item, global::Item>.DoDelete(row);

public ulong Clear() =>
global::SpacetimeDB.Internal.ITableView<Item, global::Item>.DoClear();

public sealed class KeyUniqueIndex : UniqueIndex<Item, global::Item, ItemKey, ItemKey.BSATN>
{
internal KeyUniqueIndex()
: base("Item_Key_idx_btree") { }

public global::Item? Find(ItemKey key) => FindSingle(key);

public global::Item Update(global::Item row) => DoUpdate(row);
}

public KeyUniqueIndex Key => new();
}

public readonly struct MultiTable1
: global::SpacetimeDB.Internal.ITableView<MultiTable1, global::MultiTableRow>
{
Expand Down Expand Up @@ -2086,6 +2186,36 @@ internal FactionIndex()
internal FactionIndex Faction => new();
}

public sealed class ItemReadOnly : global::SpacetimeDB.Internal.ReadOnlyTableView<global::Item>
{
internal ItemReadOnly()
: base("Item") { }

/// <summary>
/// Returns the number of rows in this table.
///
/// This reads datastore metadata, so it runs in constant time.
/// It also takes into account modifications by the current transaction.
/// </summary>
public ulong Count => DoCount();

public sealed class KeyIndex
: global::SpacetimeDB.Internal.ReadOnlyUniqueIndex<
global::SpacetimeDB.Internal.ViewHandles.ItemReadOnly,
global::Item,
ItemKey,
ItemKey.BSATN
>
{
internal KeyIndex()
: base("Item_Key_idx_btree") { }

public global::Item? Find(ItemKey key) => FindSingle(key);
}

public KeyIndex Key => new();
}

public sealed class MultiTable1ReadOnly
: global::SpacetimeDB.Internal.ReadOnlyTableView<global::MultiTableRow>
{
Expand Down Expand Up @@ -2309,6 +2439,7 @@ public sealed partial class LocalReadOnly
internal global::SpacetimeDB.Internal.ViewHandles.BTreeMultiColumnReadOnly BTreeMultiColumn =>
new();
internal global::SpacetimeDB.Internal.ViewHandles.BTreeViewsReadOnly BTreeViews => new();
public global::SpacetimeDB.Internal.ViewHandles.ItemReadOnly Item => new();
public global::SpacetimeDB.Internal.ViewHandles.MultiTable1ReadOnly MultiTable1 => new();
public global::SpacetimeDB.Internal.ViewHandles.MultiTable2ReadOnly MultiTable2 => new();
public global::SpacetimeDB.Internal.ViewHandles.PrivateTableReadOnly PrivateTable => new();
Expand Down Expand Up @@ -2497,6 +2628,8 @@ public static void Main()
(identity, connectionId, random, time) =>
new SpacetimeDB.ProcedureContext(identity, connectionId, random, time)
);
SpacetimeDB.Internal.Module.RegisterExplicitTableName("Item", "item");

SpacetimeDB.Internal.Module.SetHandlerContextConstructor(
(random, time) => new SpacetimeDB.HandlerContext(random, time)
);
Expand Down Expand Up @@ -2525,6 +2658,10 @@ public static void Main()
global::BTreeViews,
SpacetimeDB.Internal.TableHandles.BTreeViews
>();
SpacetimeDB.Internal.Module.RegisterTable<
global::Item,
SpacetimeDB.Internal.TableHandles.Item
>();
SpacetimeDB.Internal.Module.RegisterTable<
global::MultiTableRow,
SpacetimeDB.Internal.TableHandles.MultiTable1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//HintName: Item.cs
// <auto-generated />
#nullable enable

partial struct Item : System.IEquatable<Item>, SpacetimeDB.BSATN.IStructuralReadWrite
{
public void ReadFields(System.IO.BinaryReader reader)
{
Key = BSATN.KeyRW.Read(reader);
Name = BSATN.NameRW.Read(reader);
}

public void WriteFields(System.IO.BinaryWriter writer)
{
BSATN.KeyRW.Write(writer, Key);
BSATN.NameRW.Write(writer, Name);
}

object SpacetimeDB.BSATN.IStructuralReadWrite.GetSerializer()
{
return new BSATN();
}

public override string ToString() =>
$"Item {{ Key = {SpacetimeDB.BSATN.StringUtil.GenericToString(Key)}, Name = {SpacetimeDB.BSATN.StringUtil.GenericToString(Name)} }}";

public readonly partial struct BSATN : SpacetimeDB.BSATN.IReadWrite<Item>
{
internal static readonly ItemKey.BSATN KeyRW = new();
internal static readonly SpacetimeDB.BSATN.String NameRW = new();

public Item Read(System.IO.BinaryReader reader)
{
var ___result = new Item();
___result.ReadFields(reader);
return ___result;
}

public void Write(System.IO.BinaryWriter writer, Item value)
{
value.WriteFields(writer);
}

public SpacetimeDB.BSATN.AlgebraicType.Ref GetAlgebraicType(
SpacetimeDB.BSATN.ITypeRegistrar registrar
) =>
registrar.RegisterType<Item>(_ => new SpacetimeDB.BSATN.AlgebraicType.Product(
new SpacetimeDB.BSATN.AggregateElement[]
{
new("Key", KeyRW.GetAlgebraicType(registrar)),
new("Name", NameRW.GetAlgebraicType(registrar))
}
));

SpacetimeDB.BSATN.AlgebraicType SpacetimeDB.BSATN.IReadWrite<Item>.GetAlgebraicType(
SpacetimeDB.BSATN.ITypeRegistrar registrar
) => GetAlgebraicType(registrar);
}

public override int GetHashCode()
{
var ___hashKey = Key.GetHashCode();
var ___hashName = Name == null ? 0 : Name.GetHashCode();
return ___hashKey ^ ___hashName;
}

#nullable enable
public bool Equals(Item that)
{
var ___eqKey = this.Key.Equals(that.Key);
var ___eqName = this.Name == null ? that.Name == null : this.Name.Equals(that.Name);
return ___eqKey && ___eqName;
}

public override bool Equals(object? that)
{
if (that == null)
{
return false;
}
var that_ = that as Item?;
if (((object?)that_) == null)
{
return false;
}
return Equals(that_);
}

public static bool operator ==(Item this_, Item that)
{
if (((object?)this_) == null || ((object?)that) == null)
{
return object.Equals(this_, that);
}
return this_.Equals(that);
}

public static bool operator !=(Item this_, Item that)
{
if (((object?)this_) == null || ((object?)that) == null)
{
return !object.Equals(this_, that);
}
return !this_.Equals(that);
}
#nullable restore
} // Item
Loading