๐ท Delete Data
๐ถ Unity
- ํ์ฌ ๋ฐ์ดํฐ ํ ์ด๋ธ
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Table;
using MRTK.Tutorials.AzureCloudServices.Scripts.Domain;
using UnityEngine;
using UnityEngine.Events;
namespace MRTK.Tutorials.AzureCloudServices.Scripts.Managers
{
public class DataManager : MonoBehaviour
{
public bool IsReady { get; private set; }
[Header("Base Settings")]
[SerializeField]
private string connectionString = default;
[Header("Table Settings")]
[SerializeField]
private string projectsTableName = "students";
[SerializeField]
private bool tryCreateTableOnStart = true;
[Header("Events")]
[SerializeField]
private UnityEvent onDataManagerReady = default;
[SerializeField]
private UnityEvent onDataManagerInitFailed = default;
private CloudStorageAccount storageAccount;
private CloudTableClient cloudTableClient;
private CloudTable projectsTable;
private async void Awake()
{
storageAccount = CloudStorageAccount.Parse(connectionString);
cloudTableClient = storageAccount.CreateCloudTableClient();
projectsTable = cloudTableClient.GetTableReference(projectsTableName);
if (tryCreateTableOnStart)
{
try
{
if (await projectsTable.CreateIfNotExistsAsync())
{
Debug.Log($"Created table {projectsTableName}.");
}
}
catch (StorageException ex)
{
Debug.LogError("Failed to connect with Azure Storage.\nIf you are running with the default storage emulator configuration, please make sure you have started the storage emulator.");
Debug.LogException(ex);
onDataManagerInitFailed?.Invoke();
}
}
// InsertData();
// ReadData();
DeleteData();
IsReady = true;
onDataManagerReady?.Invoke();
}
public void InsertData()
{
TableOperation operation;
TableResult result;
Student student;
student = new Student
{
PartitionKey = "00",
RowKey = "00",
Name = "OJUI",
Email = "ojui@example.com",
Address = "Developer Village"
};
operation = TableOperation.InsertOrMerge(student);
result = projectsTable.ExecuteAsync(operation).Result;
}
public async void ReadData()
{
CloudTable table = projectsTable;
string partitionKey = "02";
string rowKey = "02";
TableOperation retrieveOperation = TableOperation.Retrieve<Student>(partitionKey, rowKey);
TableResult result = await table.ExecuteAsync(retrieveOperation);
Student student = result.Result as Student;
if (student != null)
{
Debug.Log($"----- READ FUNCTION -----");
Debug.Log($"์ด๋ฆ : {student.Name}");
Debug.Log($"์ฃผ์ : {student.Address}");
}
}
public async void DeleteData()
{
CloudTable table = projectsTable;
Student entity;
entity = new Student
{
PartitionKey = "01",
RowKey = "01",
ETag = "*"
};
TableOperation retrieveOperation = TableOperation.Delete(entity);
TableResult result = await table.ExecuteAsync(retrieveOperation);
}
}
public class Student : TableEntity
{
public Student(string PartitionKey, string RowKey, string Name, string Email = null, string Address = null)
{
this.PartitionKey = PartitionKey;
this.RowKey = RowKey;
this.Name = Name;
this.Email = Email;
this.Address = Address;
}
public Student() { }
public string Name { get; set; }
public string Email { get; set; }
public string Address { get; set; }
}
}
- PartitionKey:01, RowKey:01์ธ ๋ฐ์ดํฐ๋ฅผ ์ญ์
- play
- 01 ๋ฐ์ดํฐ๊ฐ ์ญ์ ๋ ๊ฒ ํ์ธ
๐ถ Potal
- ์ง์ ์ญ์ ๊ฐ๋ฅ
- ์ญ์ ํ๊ณ ์ถ์ ๋ฐ์ดํฐ ํด๋ฆญ
- Delete Entities
- ๋ฐ์ดํฐ๊ฐ ์ญ์ ๋ ๊ฒ ํ์ธazure
'Unity > Database' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[์ ๋ํฐ Json ํ์ฑ] Newtonsoft.Json & Unity JSON Utility (0) | 2022.05.26 |
---|---|
03. Azure CosmosDB - Read (0) | 2021.08.29 |
02. Azure CosmosDB - Insert (0) | 2021.08.28 |
01. Azure CosmosDB Settings (0) | 2021.08.21 |
00. Azure ์ฒดํ๊ณ์ ํ์ฑํ (0) | 2021.08.20 |