-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.d
52 lines (37 loc) · 1.12 KB
/
app.d
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
import std.algorithm;
import std.datetime;
import std.stdio;
import miniorm;
struct Foo {
ulong id;
string text;
SysTime ts;
}
struct Baz {
string one;
double two;
}
struct Bar {
ulong id;
float value;
Baz baz;
}
enum schema = buildSchema!(Foo, Bar);
void main() {
auto db = Miniorm("test.db");
db.log = (string v) => writeln(v);
db.run(schema);
writeln("Foo count: ", db.run(count!Foo));
foreach (v; db.run(select!Foo.where("text = :hello", Bind("hello")), "hello"))
writeln(v);
writeln;
writeln("Bar count: ", db.run(count!Bar));
foreach (v; db.run(select!Bar.where("value < 3")))
writeln(v);
db.run(delete_!Foo.where("ts < :ts", Bind("ts")), Clock.currTime);
db.run(insert!Foo, Foo(0, "hello", Clock.currTime), Foo(20, "world", Clock.currTime));
db.run(insert!Foo, Foo(0, "hello", Clock.currTime), Foo(0, "world", Clock.currTime));
import std.random : uniform;
db.run(insert!Bar, Bar(0, uniform(0, 10), Baz("one", 3.14)));
db.run(insertOrReplace!Foo, Foo(1, "hello", Clock.currTime), Foo(3, "world", Clock.currTime));
}