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;

// }

//}

相关推荐
以后不吃煲仔饭9 分钟前
Java基础夯实——2.7 线程上下文切换
java·开发语言
进阶的架构师10 分钟前
2024年Java面试题及答案整理(1000+面试题附答案解析)
java·开发语言
前端拾光者14 分钟前
利用D3.js实现数据可视化的简单示例
开发语言·javascript·信息可视化
程序猿阿伟16 分钟前
《C++ 实现区块链:区块时间戳的存储与验证机制解析》
开发语言·c++·区块链
傻啦嘿哟34 分钟前
如何使用 Python 开发一个简单的文本数据转换为 Excel 工具
开发语言·python·excel
大数据编程之光38 分钟前
Flink Standalone集群模式安装部署全攻略
java·大数据·开发语言·面试·flink
初九之潜龙勿用38 分钟前
C#校验画布签名图片是否为空白
开发语言·ui·c#·.net
Dola_Pan1 小时前
C语言:数组转换指针的时机
c语言·开发语言·算法
ExiFengs1 小时前
实际项目Java1.8流处理, Optional常见用法
java·开发语言·spring
paj1234567891 小时前
JDK1.8新增特性
java·开发语言