1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

orm: fix time (#11026)

This commit is contained in:
Louis Schmieder
2021-08-03 04:17:00 +02:00
committed by GitHub
parent 6dcf72fe9b
commit a55ba08fad
7 changed files with 52 additions and 15 deletions

View File

@@ -342,7 +342,7 @@ pub fn orm_table_gen(table string, para string, defaults bool, def_unique_len in
mut field_name := sql_field_name(field)
mut ctyp := sql_from_v(sql_field_type(field)) or {
field_name = '${field_name}_id'
sql_from_v(8) ?
sql_from_v(7) ?
}
if ctyp == '' {
return error('Unknown type ($field.typ) for field $field.name in struct $table')

View File

@@ -1,6 +1,7 @@
// import os
// import pg
// import term
import time
import sqlite
struct Module {
@@ -23,6 +24,11 @@ struct Foo {
age int
}
struct TestTime {
id int [primary; sql: serial]
create time.Time
}
fn test_orm_sqlite() {
db := sqlite.connect(':memory:') or { panic(err) }
db.exec('drop table if exists User')
@@ -287,4 +293,24 @@ fn test_orm_sqlite() {
}
assert first.age == 60
sql db {
create table TestTime
}
tnow := time.now()
time_test := TestTime{
create: tnow
}
sql db {
insert time_test into TestTime
}
data := sql db {
select from TestTime where create == tnow
}
assert data.len == 1
}