65 lines
1.8 KiB
C#
65 lines
1.8 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Storage;
|
|
using Server.System;
|
|
|
|
namespace Server.SQL
|
|
{
|
|
public abstract class SQL<T> : DbContext where T : class
|
|
{
|
|
|
|
public abstract DbSet<T> table { get; set; }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
if (!optionsBuilder.IsConfigured)
|
|
{
|
|
optionsBuilder.UseNpgsql(Statics.SQL_URL);
|
|
// 다른 옵션들을 추가할 수 있습니다.
|
|
}
|
|
}
|
|
|
|
public void Insert(T newData)
|
|
{
|
|
table.Add(newData);
|
|
SaveChanges();
|
|
}
|
|
|
|
public void Insert(List<T> newData)
|
|
{
|
|
table.AddRange(newData);
|
|
SaveChanges();
|
|
}
|
|
|
|
// Update 예시
|
|
// 각자 상황에 맞게 작성해서 사용할것
|
|
//public void Update(string column, string data)
|
|
//{
|
|
// var existingData = table.FirstOrDefault(data => data.name == "example");
|
|
|
|
// if (existingData != null)
|
|
// {
|
|
// existingData.data = "updated data";
|
|
// dbContext.SaveChanges();
|
|
// }
|
|
//}
|
|
|
|
public List<T> Select()
|
|
{
|
|
return table.ToList();
|
|
}
|
|
|
|
public abstract List<T> SelectUid(long user_id);
|
|
|
|
// Select 예시
|
|
// 각자 상황에 맞게 작성해서 사용할것
|
|
//public DynamicData GetDataByName(string name)
|
|
//{
|
|
// return table.SingleOrDefault(data => data.name == name);
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 특정 상황에 트렌젝션 롤백을 해야할때 사용
|
|
/// </summary>
|
|
public IDbContextTransaction Transaction { get { return Database.BeginTransaction(); } }
|
|
}
|
|
} |