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;

// }

//}

相关推荐
杨荧10 分钟前
【JAVA毕业设计】基于Vue和SpringBoot的服装商城系统学科竞赛管理系统
java·开发语言·vue.js·spring boot·spring cloud·java-ee·kafka
白子寰16 分钟前
【C++打怪之路Lv14】- “多态“篇
开发语言·c++
王俊山IT28 分钟前
C++学习笔记----10、模块、头文件及各种主题(一)---- 模块(5)
开发语言·c++·笔记·学习
为将者,自当识天晓地。30 分钟前
c++多线程
java·开发语言
小政爱学习!32 分钟前
封装axios、环境变量、api解耦、解决跨域、全局组件注入
开发语言·前端·javascript
k09331 小时前
sourceTree回滚版本到某次提交
开发语言·前端·javascript
神奇夜光杯1 小时前
Python酷库之旅-第三方库Pandas(202)
开发语言·人工智能·python·excel·pandas·标准库及第三方库·学习与成长
Themberfue1 小时前
Java多线程详解⑤(全程干货!!!)线程安全问题 || 锁 || synchronized
java·开发语言·线程·多线程·synchronized·
plmm烟酒僧1 小时前
Windows下QT调用MinGW编译的OpenCV
开发语言·windows·qt·opencv
测试界的酸菜鱼1 小时前
Python 大数据展示屏实例
大数据·开发语言·python