-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.nim
54 lines (48 loc) · 2.09 KB
/
calendar.nim
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
import strutils
when defined(postgres): import db_postgres
else: import db_sqlite
include "calendar.tmpl"
const
sql_now =
when defined(postgres): "(extract(epoch from now()))"
else: "(strftime('%s', 'now'))"
sql_timestamp =
when defined(postgres): "integer"
else: "timestamp"
sql_id =
when defined(postgres): "integer generated by default as identity"
else: "integer"
sql_bool =
when defined(postgres): "boolean" # 0 / 1 | true / false
else: "integer" # 0 / 1
calendarTable = sql("""
create table if not exists calendar(
id $3 primary key,
title varchar(25) not null,
description varchar(300) not null,
color varchar(9) not null,
email varchar(254) not null,
web varchar(300) not null,
location varchar(300) not null,
maxPeople integer not null default 2,
eventDate $2 not null default $1,
creation $2 not null default $1,
isRemote $4 not null default 0,
isFree $4 not null default 0,
isMinorsOk $4 not null default 0,
hasA11y $4 not null default 0,
hasBikePark $4 not null default 0,
hasCarPark $4 not null default 0,
hasFood $4 not null default 0,
hasDrink $4 not null default 0,
hasBTC $4 not null default 0,
needNotebook $4 not null default 0,
isWeatherOk $4 not null default 1,
hasPower $4 not null default 1,
hasWifi $4 not null default 1,
hasAC $4 not null default 1,
hasBathroom $4 not null default 1,
hasSit $4 not null default 1
);""".format(sql_now, sql_timestamp, sql_id, sql_bool))
proc calendarStart*(db: DbConn) =
exec(db, calendarTable)