ORM-CORM

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;

// }

//}

相关推荐
古希腊掌管学习的神20 分钟前
[LeetCode-Python版]相向双指针——611. 有效三角形的个数
开发语言·python·leetcode
赵钰老师21 分钟前
【R语言遥感技术】“R+遥感”的水环境综合评价方法
开发语言·数据分析·r语言
就爱学编程29 分钟前
重生之我在异世界学编程之C语言小项目:通讯录
c语言·开发语言·数据结构·算法
Oneforlove_twoforjob1 小时前
【Java基础面试题025】什么是Java的Integer缓存池?
java·开发语言·缓存
emoji1111111 小时前
前端对页面数据进行缓存
开发语言·前端·javascript
每天都要学信号1 小时前
Python(第一天)
开发语言·python
TENET信条1 小时前
day53 第十一章:图论part04
开发语言·c#·图论
生信圆桌1 小时前
【生信圆桌x教程系列】如何安装 seurat V5版本R包,最详细安装手册
开发语言·r语言
IT猿手1 小时前
最新高性能多目标优化算法:多目标麋鹿优化算法(MOEHO)求解TP1-TP10及工程应用---盘式制动器设计,提供完整MATLAB代码
开发语言·深度学习·算法·机器学习·matlab·多目标算法
单片机学习之路1 小时前
【C语言】结构
c语言·开发语言·stm32·单片机·51单片机