Skip to content

Commit 20e99dc

Browse files
merge conflicts
2 parents f093966 + f4cd467 commit 20e99dc

20 files changed

Lines changed: 429 additions & 485 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.pfx
66
npm-debug.log
77
Program/node_modules
8+
*.db
89

910
# User-specific files
1011
*.suo

Program/Demo.db

-8 KB
Binary file not shown.

Program/Program.cs

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
using System.Data;
1212
using Dapper;
1313
using System.Data.SQLite;
14+
using static SqlKata.Expressions;
15+
using System.IO;
1416

1517
namespace Program
1618
{
@@ -33,49 +35,70 @@ private class Installment
3335
static void Main(string[] args)
3436
{
3537

36-
IDbConnection connection = new SqlConnection(
37-
"Server=tcp:localhost,1433;Initial Catalog=Lite;User ID=sa;Password=P@ssw0rd"
38-
);
38+
var db = SqlLiteQueryFactory();
3939

40-
// SQLiteConnection.CreateFile("Demo.db");
40+
var id = db.Query("accounts").InsertGetId<int>(new
41+
{
42+
name = "new Account",
43+
currency_id = "USD",
44+
created_at = DateTime.UtcNow
45+
});
46+
47+
var id2 = db.Select<int>("insert into accounts(name, currency_id, created_at) values ('account 2','usd','2019-01-01 20:00:00');select last_insert_rowid();");
48+
49+
Console.WriteLine($"last id is: {id}");
50+
Console.WriteLine($"last id2 is: {id2.First()}");
51+
52+
}
53+
54+
private static void log(Compiler compiler, Query query)
55+
{
56+
var compiled = compiler.Compile(query);
57+
Console.WriteLine(compiled.ToString());
58+
Console.WriteLine(JsonConvert.SerializeObject(compiled.Bindings));
59+
}
4160

42-
// connection = new SQLiteConnection("Data Source=Demo.db");
61+
private static QueryFactory SqlLiteQueryFactory()
62+
{
63+
var compiler = new SqliteCompiler();
64+
65+
var connection = new SQLiteConnection("Data Source=Demo.db");
4366

44-
var db = new QueryFactory(connection, new SqlServerCompiler());
67+
var db = new QueryFactory(connection, compiler);
4568

4669
db.Logger = result =>
4770
{
4871
Console.WriteLine(result.ToString());
4972
};
5073

51-
/*
52-
var accounts = db.Query("Accounts")
53-
.WhereNotNull("BankId")
54-
.Include("bank",
55-
db.Query("Banks").Include("Country", db.Query("Countries"))
56-
.Select("Id", "Name", "CountryId")
57-
)
58-
.Select("Id", "Name", "BankId")
59-
.OrderByDesc("Id").Limit(10).Get();
60-
*/
61-
62-
var includedAccountsQuery = db.Query("Accounts").Limit(2)
63-
.IncludeMany("Transactions", db.Query("Transactions"))
64-
.Include("Company", db.Query("Companies"));
65-
66-
var bank = db.Query("Banks as Icon")
67-
.IncludeMany("Accounts", includedAccountsQuery, "BankId")
68-
.WhereExists(q => q.From("Accounts").WhereColumns("Accounts.BankId", "=", "Icon.Id"))
69-
.Limit(1)
70-
.Get();
71-
72-
Console.WriteLine(JsonConvert.SerializeObject(bank, Formatting.Indented));
74+
if (!File.Exists("Demo.db"))
75+
{
76+
Console.WriteLine("db not exists creating db");
7377

78+
SQLiteConnection.CreateFile("Demo.db");
79+
80+
db.Statement("create table accounts(id integer primary key autoincrement, name varchar, currency_id varchar, created_at datetime);");
81+
82+
}
83+
84+
return db;
7485
}
7586

76-
private static void log(Compiler compiler, Query query)
87+
private static QueryFactory SqlServerQueryFactory()
7788
{
78-
Console.WriteLine(compiler.Compile(query).ToString());
89+
var compiler = new PostgresCompiler();
90+
var connection = new SqlConnection(
91+
"Server=tcp:localhost,1433;Initial Catalog=Lite;User ID=sa;Password=P@ssw0rd"
92+
);
93+
94+
var db = new QueryFactory(connection, compiler);
95+
96+
db.Logger = result =>
97+
{
98+
Console.WriteLine(result.ToString());
99+
};
100+
101+
return db;
79102
}
80103

81104
}

0 commit comments

Comments
 (0)