chaosbot/ChaosBot/Attribute/DBEntity.cs

49 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using Microsoft.Data.Sqlite;
namespace ChaosBot.Attribute
{
[AttributeUsage(AttributeTargets.Class)]
public class DBEntity : System.Attribute
{
public readonly string Table;
// Yeah... this table does not exist elsewhere except human-readable documentation
public static readonly Dictionary<Type, SqliteType> DataTypes = new Dictionary<Type, SqliteType>
{
{typeof(bool), SqliteType.Integer},
{typeof(byte), SqliteType.Integer},
{typeof(byte[]), SqliteType.Blob},
{typeof(char), SqliteType.Text},
{typeof(DateTime), SqliteType.Text},
{typeof(DateTimeOffset), SqliteType.Text},
{typeof(Decimal), SqliteType.Text},
{typeof(Double), SqliteType.Real},
{typeof(Guid), SqliteType.Text},
{typeof(Int16), SqliteType.Integer},
{typeof(Int32), SqliteType.Integer},
{typeof(Int64), SqliteType.Integer},
{typeof(SByte), SqliteType.Integer},
{typeof(Single), SqliteType.Real},
{typeof(String), SqliteType.Text},
{typeof(TimeSpan), SqliteType.Text},
{typeof(UInt16), SqliteType.Integer},
{typeof(UInt32), SqliteType.Integer},
{typeof(UInt64), SqliteType.Integer}
};
public static readonly Dictionary<Type, string> ConstrainNames = new Dictionary<Type, string>
{
{typeof(DBNotNull), "nn"},
{typeof(DBUnique), "uq"},
{typeof(DBPrimaryKey), "pk"},
{typeof(DBAutoIncrement), "ai"},
};
public DBEntity(string table)
{
this.Table = table;
}
}
}