-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
95 lines (82 loc) · 4.18 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using SqlBuilder;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
namespace SqlBuilderTest
{
internal class Program
{
private static void Main()
{
SqlBuild.Configure(
new SqlBuildOptions
{
Provider = DatabaseProvider.Oracle10GOrLater
}
);
var createTableSql = SqlBuild.CreateTable<Users>();
Console.WriteLine(createTableSql.GenerateStatement() + Environment.NewLine);
var selectSql = SqlBuild.Select<Users>(false)
.AddColumns<Users>("username", "email")
.Join<Addresses, Users>("userid", "id")
.AddColumns<Addresses>("postcode", "street");
selectSql.Where(new BuiltSqlCondition()
.BeginBlock()
.AddCondition<Users>("lastname", "=", "Jones", DbType.String)
.And()
.AddCondition<Addresses>("state", "=", "Ohio", DbType.String)
.EndBlock()
.Or()
.AddCondition<Users>("id", ">", "50", DbType.Int32))
.OrderBy()
.SortBy<Users>("firstname", SqlSortMode.DESCENDING)
.Finish();
Console.WriteLine(selectSql + Environment.NewLine);
var insertSql = SqlBuild.InsertInto<Users>("username", "password", "email")
.AddValues(
new BuiltValueList<Users>(new List<string> {"username", "password", "email"})
.AddValueFor("username", "rakijah")
.AddValueFor("password", "dGhlIGdhbWU=")
.AddValueFor("email", "rakijah@fakemail.com")
)
.AddRow("user2", "ZmVsbCBmb3IgaXQgYWdhaW4=", "user2@fakemail.com");
Console.WriteLine(insertSql + Environment.NewLine);
var deleteSql = SqlBuild.Delete()
.From<Users>()
.Where(new BuiltSqlCondition().AddCondition<Users>("id", "<", "10", DbType.Int32));
Console.WriteLine(deleteSql + Environment.NewLine);
var alterTableSql = SqlBuild.AlterTable<Users>()
.Add("firstname", "varchar(50)")
.Add("lastname", "varchar(50)")
.Drop("fullname")
.ChangeColumnType("username", "VARCHAR(255)");
Console.WriteLine(alterTableSql + Environment.NewLine);
Console.ReadLine();
/*
SqlConnection connection = new SqlConnection("Data Source=Example;User Id=admin;password=password;");
connection.Open();
var cmd = selectSql.GenerateCommand(connection);
Console.WriteLine($"CommandText: {cmd.CommandText}");
foreach (DbParameter param in cmd.Parameters)
{
Console.WriteLine($"Name: {param.ParameterName} Value: {param.Value}, Type: {param.DbType}");
}
Console.ReadLine();
EntityFetcher fetcher = new EntityFetcher(connection);
var usersBetween20And40 = fetcher.All<Users>(
new BuiltSqlCondition()
.AddCondition<Users>("id", ">", "20")
.And()
.AddCondition<Users>("id", "<", "40")
);
foreach(var user in usersBetween20And40)
{
Console.WriteLine($"Name: {user.FirstName} {user.LastName}, Email: {user.Email}");
}
Console.ReadLine();
//*/
}
}
}