Skip to content

Commit be8f39f

Browse files
author
Wood, Roger C
committed
Merging upstream master.
2 parents 3535479 + 4f74f04 commit be8f39f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2706
-1929
lines changed

.editorconfig

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: ['ahmad-moussawi']
4+
patreon: # Replace with a single Patreon username
5+
open_collective: sqlkata
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

.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

.travis.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

Directory.build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<Import Project="version.props"/>
33
<PropertyGroup>
4-
<Copyright>2017 SqlKata</Copyright>
4+
<Copyright>2020 SqlKata</Copyright>
55
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
66
<GenerateDocumentationFile>false</GenerateDocumentationFile>
77
<!--<AssemblyOriginatorKeyFile>../SqlKata.snk</AssemblyOriginatorKeyFile>-->

Program/Demo.db

-8 KB
Binary file not shown.

Program/Program.cs

Lines changed: 62 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
{
@@ -32,50 +34,80 @@ private class Installment
3234

3335
static void Main(string[] args)
3436
{
37+
using (var db = SqlLiteQueryFactory())
38+
{
39+
var query = db.Query("accounts")
40+
.Where("balance", ">", 0)
41+
.GroupBy("balance")
42+
.Limit(10);
3543

36-
IDbConnection connection = new SqlConnection(
37-
"Server=tcp:localhost,1433;Initial Catalog=Lite;User ID=sa;Password=P@ssw0rd"
38-
);
44+
var accounts = query.Clone().Get();
45+
Console.WriteLine(JsonConvert.SerializeObject(accounts, Formatting.Indented));
3946

40-
// SQLiteConnection.CreateFile("Demo.db");
47+
var exists = query.Clone().Exists();
48+
Console.WriteLine(exists);
49+
}
50+
}
4151

42-
// connection = new SQLiteConnection("Data Source=Demo.db");
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+
}
4358

44-
var db = new QueryFactory(connection, new SqlServerCompiler());
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);
4566

4667
db.Logger = result =>
4768
{
4869
Console.WriteLine(result.ToString());
4970
};
5071

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));
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;
7393

7494
}
7595

76-
private static void log(Compiler compiler, Query query)
96+
private static QueryFactory SqlServerQueryFactory()
7797
{
78-
Console.WriteLine(compiler.Compile(query).ToString());
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;
79111
}
80112

81113
}

Program/index.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

Program/package.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)