game: testing the backend
This commit is contained in:
parent
72956d592a
commit
4afc19d8b4
2 changed files with 47 additions and 1 deletions
|
@ -1,5 +1,51 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using Supabase;
|
||||
using Supabase.Postgrest;
|
||||
using Supabase.Postgrest.Attributes;
|
||||
using Supabase.Postgrest.Models;
|
||||
|
||||
public class Backend : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private string url;
|
||||
[SerializeField] private string anonKey;
|
||||
|
||||
private async void Start()
|
||||
{
|
||||
var options = new SupabaseOptions
|
||||
{
|
||||
AutoConnectRealtime = true
|
||||
};
|
||||
|
||||
var client = new Supabase.Client(url, anonKey, options);
|
||||
await client.InitializeAsync();
|
||||
var test = new Test
|
||||
{
|
||||
Name = "John",
|
||||
Score = 100
|
||||
};
|
||||
await client.From<Test>().Insert(test, new QueryOptions { Returning = QueryOptions.ReturnType.Representation })
|
||||
.ContinueWith(task =>
|
||||
{
|
||||
if (task.IsCompletedSuccessfully)
|
||||
{
|
||||
var result = task.Result;
|
||||
Debug.Log(result.Models[0].Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError(task.Exception);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Table("test")]
|
||||
public class Test : BaseModel
|
||||
{
|
||||
[Column("name")] public string Name { get; set; }
|
||||
|
||||
[Column("score")] public int Score { get; set; }
|
||||
}
|
Loading…
Add table
Reference in a new issue