|
1 |
| -using System; |
2 |
| -using System.Collections.Generic; |
3 |
| -using SqlKata; |
4 |
| -using SqlKata.Compilers; |
5 |
| -using SqlKata.Execution; |
6 |
| -using System.Data.SqlClient; |
7 |
| -using System.Threading.Tasks; |
8 |
| -using System.Linq; |
9 |
| -using Newtonsoft.Json; |
10 |
| -using Npgsql; |
11 |
| -using System.Data; |
12 |
| -using Dapper; |
13 |
| -using System.Data.SQLite; |
14 |
| -using static SqlKata.Expressions; |
15 |
| -using System.IO; |
16 |
| - |
17 |
| -namespace Program |
18 |
| -{ |
19 |
| - class Program |
20 |
| - { |
21 |
| - private class Loan |
22 |
| - { |
23 |
| - public string Id { get; set; } |
24 |
| - public string Name { get; set; } |
25 |
| - public List<Installment> Installments { get; set; } = new List<Installment>(); |
26 |
| - } |
27 |
| - |
28 |
| - private class Installment |
29 |
| - { |
30 |
| - public string Id { get; set; } |
31 |
| - public string LoanId { get; set; } |
32 |
| - public int DaysCount { get; set; } |
33 |
| - } |
34 |
| - |
35 |
| - static void Main(string[] args) |
36 |
| - { |
37 |
| - using (var db = SqlLiteQueryFactory()) |
38 |
| - { |
39 |
| - var query = db.Query("accounts") |
40 |
| - .Where("balance", ">", 0) |
41 |
| - .GroupBy("balance") |
42 |
| - .Limit(10); |
43 |
| - |
44 |
| - var accounts = query.Clone().Get(); |
45 |
| - Console.WriteLine(JsonConvert.SerializeObject(accounts, Formatting.Indented)); |
46 |
| - |
47 |
| - var exists = query.Clone().Exists(); |
48 |
| - Console.WriteLine(exists); |
49 |
| - } |
50 |
| - } |
51 |
| - |
52 |
| - private static void log(Compiler compiler, Query query) |
53 |
| - { |
54 |
| - var compiled = compiler.Compile(query); |
55 |
| - Console.WriteLine(compiled.ToString()); |
56 |
| - Console.WriteLine(JsonConvert.SerializeObject(compiled.Bindings)); |
57 |
| - } |
58 |
| - |
59 |
| - private static QueryFactory SqlLiteQueryFactory() |
60 |
| - { |
61 |
| - var compiler = new SqliteCompiler(); |
62 |
| - |
63 |
| - var connection = new SQLiteConnection("Data Source=Demo.db"); |
64 |
| - |
65 |
| - var db = new QueryFactory(connection, compiler); |
66 |
| - |
67 |
| - db.Logger = result => |
68 |
| - { |
69 |
| - Console.WriteLine(result.ToString()); |
70 |
| - }; |
71 |
| - |
72 |
| - if (!File.Exists("Demo.db")) |
73 |
| - { |
74 |
| - Console.WriteLine("db not exists creating db"); |
75 |
| - |
76 |
| - SQLiteConnection.CreateFile("Demo.db"); |
77 |
| - |
78 |
| - db.Statement("create table accounts(id integer primary key autoincrement, name varchar, currency_id varchar, balance decimal, created_at datetime);"); |
79 |
| - for (var i = 0; i < 10; i++) |
80 |
| - { |
81 |
| - db.Statement("insert into accounts(name, currency_id, balance, created_at) values(@name, @currency, @balance, @date)", new |
82 |
| - { |
83 |
| - name = $"Account {i}", |
84 |
| - currency = "USD", |
85 |
| - balance = 100 * i * 1.1, |
86 |
| - date = DateTime.UtcNow, |
87 |
| - }); |
88 |
| - } |
89 |
| - |
90 |
| - } |
91 |
| - |
92 |
| - return db; |
93 |
| - |
94 |
| - } |
95 |
| - |
96 |
| - private static QueryFactory SqlServerQueryFactory() |
97 |
| - { |
98 |
| - var compiler = new PostgresCompiler(); |
99 |
| - var connection = new SqlConnection( |
100 |
| - "Server=tcp:localhost,1433;Initial Catalog=Lite;User ID=sa;Password=P@ssw0rd" |
101 |
| - ); |
102 |
| - |
103 |
| - var db = new QueryFactory(connection, compiler); |
104 |
| - |
105 |
| - db.Logger = result => |
106 |
| - { |
107 |
| - Console.WriteLine(result.ToString()); |
108 |
| - }; |
109 |
| - |
110 |
| - return db; |
111 |
| - } |
112 |
| - |
113 |
| - } |
114 |
| -} |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using SqlKata; |
| 4 | +using SqlKata.Compilers; |
| 5 | +using SqlKata.Execution; |
| 6 | +using System.Data.SqlClient; |
| 7 | +using System.Threading.Tasks; |
| 8 | +using System.Linq; |
| 9 | +using Newtonsoft.Json; |
| 10 | +using Npgsql; |
| 11 | +using System.Data; |
| 12 | +using Dapper; |
| 13 | +using System.Data.SQLite; |
| 14 | +using static SqlKata.Expressions; |
| 15 | +using System.IO; |
| 16 | + |
| 17 | +namespace Program |
| 18 | +{ |
| 19 | + class Program |
| 20 | + { |
| 21 | + private class Loan |
| 22 | + { |
| 23 | + public string Id { get; set; } |
| 24 | + public string Name { get; set; } |
| 25 | + public List<Installment> Installments { get; set; } = new List<Installment>(); |
| 26 | + } |
| 27 | + |
| 28 | + private class Installment |
| 29 | + { |
| 30 | + public string Id { get; set; } |
| 31 | + public string LoanId { get; set; } |
| 32 | + public int DaysCount { get; set; } |
| 33 | + } |
| 34 | + |
| 35 | + static void Main(string[] args) |
| 36 | + { |
| 37 | + using (var db = SqlLiteQueryFactory()) |
| 38 | + { |
| 39 | + var query = db.Query("accounts") |
| 40 | + .Where("balance", ">", 0) |
| 41 | + .GroupBy("balance") |
| 42 | + .Limit(10); |
| 43 | + |
| 44 | + var accounts = query.Clone().Get(); |
| 45 | + Console.WriteLine(JsonConvert.SerializeObject(accounts, Formatting.Indented)); |
| 46 | + |
| 47 | + var exists = query.Clone().Exists(); |
| 48 | + Console.WriteLine(exists); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + private static void log(Compiler compiler, Query query) |
| 53 | + { |
| 54 | + var compiled = compiler.Compile(query); |
| 55 | + Console.WriteLine(compiled.ToString()); |
| 56 | + Console.WriteLine(JsonConvert.SerializeObject(compiled.Bindings)); |
| 57 | + } |
| 58 | + |
| 59 | + private static QueryFactory SqlLiteQueryFactory() |
| 60 | + { |
| 61 | + var compiler = new SqliteCompiler(); |
| 62 | + |
| 63 | + var connection = new SQLiteConnection("Data Source=Demo.db"); |
| 64 | + |
| 65 | + var db = new QueryFactory(connection, compiler); |
| 66 | + |
| 67 | + db.Logger = result => |
| 68 | + { |
| 69 | + Console.WriteLine(result.ToString()); |
| 70 | + }; |
| 71 | + |
| 72 | + if (!File.Exists("Demo.db")) |
| 73 | + { |
| 74 | + Console.WriteLine("db not exists creating db"); |
| 75 | + |
| 76 | + SQLiteConnection.CreateFile("Demo.db"); |
| 77 | + |
| 78 | + db.Statement("create table accounts(id integer primary key autoincrement, name varchar, currency_id varchar, balance decimal, created_at datetime);"); |
| 79 | + for (var i = 0; i < 10; i++) |
| 80 | + { |
| 81 | + db.Statement("insert into accounts(name, currency_id, balance, created_at) values(@name, @currency, @balance, @date)", new |
| 82 | + { |
| 83 | + name = $"Account {i}", |
| 84 | + currency = "USD", |
| 85 | + balance = 100 * i * 1.1, |
| 86 | + date = DateTime.UtcNow, |
| 87 | + }); |
| 88 | + } |
| 89 | + |
| 90 | + } |
| 91 | + |
| 92 | + return db; |
| 93 | + |
| 94 | + } |
| 95 | + |
| 96 | + private static QueryFactory SqlServerQueryFactory() |
| 97 | + { |
| 98 | + var compiler = new PostgresCompiler(); |
| 99 | + var connection = new SqlConnection( |
| 100 | + "Server=tcp:localhost,1433;Initial Catalog=Lite;User ID=sa;Password=P@ssw0rd" |
| 101 | + ); |
| 102 | + |
| 103 | + var db = new QueryFactory(connection, compiler); |
| 104 | + |
| 105 | + db.Logger = result => |
| 106 | + { |
| 107 | + Console.WriteLine(result.ToString()); |
| 108 | + }; |
| 109 | + |
| 110 | + return db; |
| 111 | + } |
| 112 | + |
| 113 | + } |
| 114 | +} |
0 commit comments