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

orm,sqlite,mysql,pg: cleanup import v.ast, using typeof[Type]()

This commit is contained in:
Delyan Angelov 2022-12-07 12:26:41 +02:00
parent 4eb81d2f05
commit 458e68e196
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
5 changed files with 49 additions and 54 deletions

View File

@ -1,7 +1,6 @@
import orm
import mysql
import time
import v.ast
struct TestCustomSqlType {
id int [primary; sql: serial]
@ -51,7 +50,7 @@ fn test_mysql_orm() {
db.create('Test', [
orm.TableField{
name: 'id'
typ: ast.int_type_idx
typ: typeof[int]().idx
attrs: [
StructAttribute{
name: 'primary'
@ -66,12 +65,12 @@ fn test_mysql_orm() {
},
orm.TableField{
name: 'name'
typ: ast.string_type_idx
typ: typeof[string]().idx
attrs: []
},
orm.TableField{
name: 'age'
typ: ast.int_type_idx
typ: typeof[int]().idx
},
]) or { panic(err) }
@ -84,11 +83,11 @@ fn test_mysql_orm() {
table: 'Test'
has_where: true
fields: ['id', 'name', 'age']
types: [ast.int_type_idx, ast.string_type_idx, ast.i64_type_idx]
types: [typeof[int]().idx, typeof[string]().idx, typeof[i64]().idx]
}, orm.QueryData{}, orm.QueryData{
fields: ['name', 'age']
data: [orm.Primitive('Louis'), i64(101)]
types: [ast.string_type_idx, ast.i64_type_idx]
types: [typeof[string]().idx, typeof[i64]().idx]
is_and: [true, true]
kinds: [.eq, .eq]
}) or { panic(err) }

View File

@ -1,39 +1,38 @@
module orm
import time
import v.ast
pub const (
num64 = [ast.i64_type_idx, ast.u64_type_idx]
num64 = [typeof[i64]().idx, typeof[u64]().idx]
nums = [
ast.i8_type_idx,
ast.i16_type_idx,
ast.int_type_idx,
ast.u8_type_idx,
ast.u16_type_idx,
ast.u32_type_idx,
ast.bool_type_idx,
typeof[i8]().idx,
typeof[i16]().idx,
typeof[int]().idx,
typeof[u8]().idx,
typeof[u16]().idx,
typeof[u32]().idx,
typeof[bool]().idx,
]
float = [
ast.f32_type_idx,
ast.f64_type_idx,
typeof[f32]().idx,
typeof[f64]().idx,
]
type_string = ast.string_type_idx
type_string = typeof[string]().idx
time = -2
serial = -1
type_idx = {
'i8': ast.i8_type_idx
'i16': ast.i16_type_idx
'int': ast.int_type_idx
'i64': ast.i64_type_idx
'u8': ast.u8_type_idx
'u16': ast.u16_type_idx
'u32': ast.u32_type_idx
'u64': ast.u64_type_idx
'f32': ast.f32_type_idx
'f64': ast.f64_type_idx
'bool': ast.bool_type_idx
'string': ast.string_type_idx
'i8': typeof[i8]().idx
'i16': typeof[i16]().idx
'int': typeof[int]().idx
'i64': typeof[i64]().idx
'u8': typeof[u8]().idx
'u16': typeof[u16]().idx
'u32': typeof[u32]().idx
'u64': typeof[u64]().idx
'f32': typeof[f32]().idx
'f64': typeof[f64]().idx
'bool': typeof[bool]().idx
'string': typeof[string]().idx
}
string_max_len = 2048
)

View File

@ -1,5 +1,4 @@
import orm
import v.ast
fn test_orm_stmt_gen_update() {
query, _ := orm.orm_stmt_gen('Test', "'", .update, true, '?', 0, orm.QueryData{
@ -121,7 +120,7 @@ fn test_orm_table_gen() {
query := orm.orm_table_gen('test_table', "'", true, 0, [
orm.TableField{
name: 'id'
typ: ast.int_type_idx
typ: typeof[int]().idx
default_val: '10'
attrs: [
StructAttribute{
@ -137,11 +136,11 @@ fn test_orm_table_gen() {
},
orm.TableField{
name: 'test'
typ: ast.string_type_idx
typ: typeof[string]().idx
},
orm.TableField{
name: 'abc'
typ: ast.i64_type_idx
typ: typeof[i64]().idx
default_val: '6754'
},
], sql_type_from_v, false) or { panic(err) }
@ -150,7 +149,7 @@ fn test_orm_table_gen() {
alt_query := orm.orm_table_gen('test_table', "'", true, 0, [
orm.TableField{
name: 'id'
typ: ast.int_type_idx
typ: typeof[int]().idx
default_val: '10'
attrs: [
StructAttribute{
@ -166,11 +165,11 @@ fn test_orm_table_gen() {
},
orm.TableField{
name: 'test'
typ: ast.string_type_idx
typ: typeof[string]().idx
},
orm.TableField{
name: 'abc'
typ: ast.i64_type_idx
typ: typeof[i64]().idx
default_val: '6754'
},
], sql_type_from_v, true) or { panic(err) }
@ -179,7 +178,7 @@ fn test_orm_table_gen() {
unique_query := orm.orm_table_gen('test_table', "'", true, 0, [
orm.TableField{
name: 'id'
typ: ast.int_type_idx
typ: typeof[int]().idx
default_val: '10'
attrs: [
StructAttribute{
@ -195,7 +194,7 @@ fn test_orm_table_gen() {
},
orm.TableField{
name: 'test'
typ: ast.string_type_idx
typ: typeof[string]().idx
attrs: [
StructAttribute{
name: 'unique'
@ -204,7 +203,7 @@ fn test_orm_table_gen() {
},
orm.TableField{
name: 'abc'
typ: ast.i64_type_idx
typ: typeof[i64]().idx
default_val: '6754'
},
], sql_type_from_v, false) or { panic(err) }
@ -213,7 +212,7 @@ fn test_orm_table_gen() {
mult_unique_query := orm.orm_table_gen('test_table', "'", true, 0, [
orm.TableField{
name: 'id'
typ: ast.int_type_idx
typ: typeof[int]().idx
default_val: '10'
attrs: [
StructAttribute{
@ -229,7 +228,7 @@ fn test_orm_table_gen() {
},
orm.TableField{
name: 'test'
typ: ast.string_type_idx
typ: typeof[string]().idx
attrs: [
StructAttribute{
name: 'unique'
@ -241,7 +240,7 @@ fn test_orm_table_gen() {
},
orm.TableField{
name: 'abc'
typ: ast.i64_type_idx
typ: typeof[i64]().idx
default_val: '6754'
attrs: [
StructAttribute{

View File

@ -2,7 +2,6 @@ module main
import orm
import pg
import v.ast
import time
struct TestCustomSqlType {
@ -51,7 +50,7 @@ fn test_pg_orm() {
db.create('Test', [
orm.TableField{
name: 'id'
typ: ast.string_type_idx
typ: typeof[string]().idx
is_time: false
default_val: ''
is_arr: false
@ -72,7 +71,7 @@ fn test_pg_orm() {
},
orm.TableField{
name: 'name'
typ: ast.string_type_idx
typ: typeof[string]().idx
is_time: false
default_val: ''
is_arr: false
@ -80,7 +79,7 @@ fn test_pg_orm() {
},
orm.TableField{
name: 'age'
typ: ast.i64_type_idx
typ: typeof[i64]().idx
is_time: false
default_val: ''
is_arr: false
@ -104,7 +103,7 @@ fn test_pg_orm() {
primary: 'id'
has_offset: false
fields: ['id', 'name', 'age']
types: [ast.int_type_idx, ast.string_type_idx, ast.i64_type_idx]
types: [typeof[int]().idx, typeof[string]().idx, typeof[i64]().idx]
}, orm.QueryData{}, orm.QueryData{
fields: ['name', 'age']
data: [orm.Primitive('Louis'), orm.Primitive(101)]

View File

@ -1,6 +1,5 @@
import orm
import sqlite
import v.ast
import time
struct TestCustomSqlType {
@ -35,7 +34,7 @@ fn test_sqlite_orm() {
db.create('Test', [
orm.TableField{
name: 'id'
typ: ast.int_type_idx
typ: typeof[int]().idx
attrs: [
StructAttribute{
name: 'primary'
@ -50,12 +49,12 @@ fn test_sqlite_orm() {
},
orm.TableField{
name: 'name'
typ: ast.string_type_idx
typ: typeof[string]().idx
attrs: []
},
orm.TableField{
name: 'age'
typ: ast.i64_type_idx
typ: typeof[i64]().idx
},
]) or { panic(err) }
@ -68,11 +67,11 @@ fn test_sqlite_orm() {
table: 'Test'
has_where: true
fields: ['id', 'name', 'age']
types: [ast.int_type_idx, ast.string_type_idx, ast.i64_type_idx]
types: [typeof[int]().idx, typeof[string]().idx, typeof[i64]().idx]
}, orm.QueryData{}, orm.QueryData{
fields: ['name', 'age']
data: [orm.Primitive('Louis'), i64(100)]
types: [ast.string_type_idx, ast.i64_type_idx]
types: [typeof[string]().idx, typeof[i64]().idx]
is_and: [true, true]
kinds: [.eq, .eq]
}) or { panic(err) }