using System.Collections;
using System.Data;
using System.Data.Common;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.Json.Nodes;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
//Console.WriteLine("Hello, World!");
//DB.table("table").where().eq("name", "").SelectOne();
//DB.table("name", "table").where().eq("name", "").SelectOne();
//DB.table("name", "table").where().group().eq("name", "").eqOR("","").endgroup().SelectOne();
DB.transaction.Connection.BeginTransaction();
//var mm = ( a:"111",cc:"ee");
var aa = new { x = 1, y = 2 };
DB.table("table").primary("id").update(aa);
}
}
public static class DB
{
public static DbTransaction? transaction;
public static SqlBuilder table(string tablename)
{
string sql = "SELECT * FROM" + tablename;
SqlBuilder sqlBuilder = new SqlBuilder(sql);
return sqlBuilder;
}
public static SqlBuilder table(string columns,string tablename)
{
string sql = "SELECT " + columns + " FROM" + tablename;
SqlBuilder sqlBuilder = new SqlBuilder(sql);
return sqlBuilder;
}
}
//public class JsonContent : StringContent
//{
// public JsonContent(object obj) :
// base(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json")
// { }
//}
//eq --> ==
//ne --> <>
//lt --> <
//gt --> >
//lte --> <=
//gte --> >=
//in --> in
//notIn --> not in
//like --> like
//notLike --> not like
public class SqlBuilder
{
public SqlBuilder primary(string key)
{
return this;
}
public SqlBuilder update(object obj)
{
//new JsonContent();
//JsonConvert.SerializeObject(obj);
return this;
}
public SqlBuilder insert(object obj)
{
//new JsonContent();
//JsonConvert.SerializeObject(obj);
return this;
}
public string sql { get; set; }
public SqlBuilder(string sqlText)
{
sql = sqlText;
}
public SqlBuilder where()
{
sql += " where 1=1 ";
return this;
}
public SqlBuilder group()
{
sql += " and (1=1 " ;
return this;
}
public SqlBuilder groupor()
{
sql += " or (1=1 ";
return this;
}
public SqlBuilder endgroup()
{
sql += " )";
return this;
}
public SqlBuilder eq(string columnname, string value)
{
sql += " and @" + columnname + "=" + value + " ";
return this;
}
public SqlBuilder ne(string columnname, string value)
{
sql += " and @" + columnname + "<>" + value + " ";
return this;
}
public SqlBuilder lt(string columnname, string value)
{
sql += " and @" + columnname + "<" + value + " ";
return this;
}
public SqlBuilder gt(string columnname, string value)
{
sql += " and @" + columnname + ">" + value + " ";
return this;
}
public SqlBuilder lte(string columnname, string value)
{
sql += " and @" + columnname + "<=" + value + " ";
return this;
}
public SqlBuilder gte(string columnname, string value)
{
sql += " and @" + columnname + ">=" + value + " ";
return this;
}
public SqlBuilder In(string columnname, string value)
{
sql += " and @" + columnname + "in" + value + " ";
return this;
}
public SqlBuilder notIn(string columnname, string value)
{
sql += " and @" + columnname + "not in" + value + " ";
return this;
}
public SqlBuilder like(string columnname, string value)
{
sql += " and @" + columnname + "like" + value + " ";
return this;
}
public SqlBuilder notLike(string columnname, string value)
{
sql += " and @" + columnname + "not like" + value + " ";
return this;
}
public SqlBuilder eqOR(string columnname, string value)
{
sql += " or @" + columnname + "=" + value + " ";
return this;
}
public SqlBuilder neOR(string columnname, string value)
{
sql += " or @" + columnname + "<>" + value + " ";
return this;
}
public SqlBuilder ltOR(string columnname, string value)
{
sql += " or @" + columnname + "<" + value + " ";
return this;
}
public SqlBuilder gtOR(string columnname, string value)
{
sql += " or @" + columnname + ">" + value + " ";
return this;
}
public SqlBuilder lteOR(string columnname, string value)
{
sql += " or @" + columnname + "<=" + value + " ";
return this;
}
public SqlBuilder gteOR(string columnname, string value)
{
sql += " or @" + columnname + ">=" + value + " ";
return this;
}
public SqlBuilder InOR(string columnname, string value)
{
sql += " or @" + columnname + "in" + value + " ";
return this;
}
public SqlBuilder notInOR(string columnname, string value)
{
sql += " or @" + columnname + "not in" + value + " ";
return this;
}
public SqlBuilder likeOR(string columnname, string value)
{
sql += " or @" + columnname + "like" + value + " ";
return this;
}
public SqlBuilder notLikeOR(string columnname, string value)
{
sql += " or @" + columnname + "not like" + value + " ";
return this;
}
public DataTable Select()
{
return null;
}
public DataRow SelectOne()
{
return null;
}
//public Hashtable Select()
//{
// return this;
//}
//public Hashtable SelectOne()
//{
// return this;
//}
}
}
//public class DB
//{
// public string sql { get; set; }
// public DB()
// {
// }
//}
//public static class Ext
//{
// public static SqlBuilder table(this DB db, string tablename)
// {
// SqlBuilder sqlBuilder = new SqlBuilder(db);
// db.sql = "SELECT * FROM" + tablename;
// return sqlBuilder;
// }
//}