close db connections
This commit is contained in:
parent
8c50ac5550
commit
c29a3d26a1
1 changed files with 28 additions and 3 deletions
31
src/main.v
31
src/main.v
|
@ -66,6 +66,9 @@ pub fn create_db_connection() !sqlite.DB {
|
||||||
|
|
||||||
fn get_people() ![]Person {
|
fn get_people() ![]Person {
|
||||||
mut db := create_db_connection()!
|
mut db := create_db_connection()!
|
||||||
|
defer {
|
||||||
|
db.close() or { panic(err) }
|
||||||
|
}
|
||||||
status_filter := int(Status.afgegeven)
|
status_filter := int(Status.afgegeven)
|
||||||
people := sql db {
|
people := sql db {
|
||||||
select from Person where status < status_filter
|
select from Person where status < status_filter
|
||||||
|
@ -75,6 +78,9 @@ fn get_people() ![]Person {
|
||||||
|
|
||||||
fn get_finished_count() !int {
|
fn get_finished_count() !int {
|
||||||
mut db := create_db_connection()!
|
mut db := create_db_connection()!
|
||||||
|
defer {
|
||||||
|
db.close() or { panic(err) }
|
||||||
|
}
|
||||||
people := sql db {
|
people := sql db {
|
||||||
select from Person where status == 3
|
select from Person where status == 3
|
||||||
}!
|
}!
|
||||||
|
@ -91,6 +97,9 @@ struct PerHour {
|
||||||
|
|
||||||
fn get_all() ![]Person {
|
fn get_all() ![]Person {
|
||||||
mut db := create_db_connection()!
|
mut db := create_db_connection()!
|
||||||
|
defer {
|
||||||
|
db.close() or { panic(err) }
|
||||||
|
}
|
||||||
return sql db {
|
return sql db {
|
||||||
select from Person order by id desc
|
select from Person order by id desc
|
||||||
}!
|
}!
|
||||||
|
@ -98,6 +107,9 @@ fn get_all() ![]Person {
|
||||||
|
|
||||||
fn get_last_delivered() ![]Person {
|
fn get_last_delivered() ![]Person {
|
||||||
mut db := create_db_connection()!
|
mut db := create_db_connection()!
|
||||||
|
defer {
|
||||||
|
db.close() or { panic(err) }
|
||||||
|
}
|
||||||
return sql db {
|
return sql db {
|
||||||
select from Person order by delivery_time desc limit 1
|
select from Person order by delivery_time desc limit 1
|
||||||
}!
|
}!
|
||||||
|
@ -105,6 +117,9 @@ fn get_last_delivered() ![]Person {
|
||||||
|
|
||||||
fn get_finished_per_hour() ![]PerHour {
|
fn get_finished_per_hour() ![]PerHour {
|
||||||
mut db := create_db_connection()!
|
mut db := create_db_connection()!
|
||||||
|
defer {
|
||||||
|
db.close() or { panic(err) }
|
||||||
|
}
|
||||||
people := sql db {
|
people := sql db {
|
||||||
select from Person where status == 3
|
select from Person where status == 3
|
||||||
}!
|
}!
|
||||||
|
@ -130,12 +145,13 @@ fn get_finished_per_hour() ![]PerHour {
|
||||||
|
|
||||||
fn get_ppu() !f64 {
|
fn get_ppu() !f64 {
|
||||||
mut db := create_db_connection()!
|
mut db := create_db_connection()!
|
||||||
|
defer {
|
||||||
|
db.close() or { panic(err) }
|
||||||
|
}
|
||||||
mut people := sql db {
|
mut people := sql db {
|
||||||
select from Person where status == 3
|
select from Person where status == 3
|
||||||
}!
|
}!
|
||||||
if people.len == 0 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
people.sort(a.order_time < b.order_time)
|
people.sort(a.order_time < b.order_time)
|
||||||
time_range := people.last().order_time - people.first().order_time
|
time_range := people.last().order_time - people.first().order_time
|
||||||
return people.len / time_range.hours()
|
return people.len / time_range.hours()
|
||||||
|
@ -143,6 +159,9 @@ fn get_ppu() !f64 {
|
||||||
|
|
||||||
fn get_mean_time_between_pannenkoeken() !time.Duration {
|
fn get_mean_time_between_pannenkoeken() !time.Duration {
|
||||||
mut db := create_db_connection()!
|
mut db := create_db_connection()!
|
||||||
|
defer {
|
||||||
|
db.close() or { panic(err) }
|
||||||
|
}
|
||||||
time_zero := time.Time{
|
time_zero := time.Time{
|
||||||
unix: 0
|
unix: 0
|
||||||
}
|
}
|
||||||
|
@ -154,6 +173,9 @@ fn get_mean_time_between_pannenkoeken() !time.Duration {
|
||||||
|
|
||||||
fn status_update(user_id int) !Person {
|
fn status_update(user_id int) !Person {
|
||||||
mut db := create_db_connection()!
|
mut db := create_db_connection()!
|
||||||
|
defer {
|
||||||
|
db.close() or { panic(err) }
|
||||||
|
}
|
||||||
people := sql db {
|
people := sql db {
|
||||||
select from Person where id == user_id
|
select from Person where id == user_id
|
||||||
}!
|
}!
|
||||||
|
@ -171,6 +193,9 @@ fn status_update(user_id int) !Person {
|
||||||
|
|
||||||
fn add_person(name string, remark string) ! {
|
fn add_person(name string, remark string) ! {
|
||||||
mut db := create_db_connection()!
|
mut db := create_db_connection()!
|
||||||
|
defer {
|
||||||
|
db.close() or { panic(err) }
|
||||||
|
}
|
||||||
people := sql db {
|
people := sql db {
|
||||||
select from Person where name == name && status < 3
|
select from Person where name == name && status < 3
|
||||||
}!
|
}!
|
||||||
|
|
Loading…
Reference in a new issue