From a5a80affb14f073254dbba459efaa3c84e219767 Mon Sep 17 00:00:00 2001 From: itsumura-h Date: Sun, 10 Dec 2023 10:42:35 +0000 Subject: [PATCH 1/6] int32 to int in dbOpen --- .../libs/mariadb/mariadb_impl.nim | 21 ------------------- .../query_builder/libs/mysql/mysql_impl.nim | 21 ------------------- .../models/mariadb/mariadb_open.nim | 2 +- .../query_builder/models/mysql/mysql_open.nim | 2 +- .../models/postgres/postgres_open.nim | 2 +- .../models/sqlite/sqlite_open.nim | 4 ++-- .../models/surreal/surreal_open.nim | 2 +- .../libs/mariadb/mariadb_impl.nim | 21 ------------------- .../query_builder/libs/mysql/mysql_impl.nim | 21 ------------------- .../models/mariadb/mariadb_open.nim | 4 ++-- .../query_builder/models/mysql/mysql_open.nim | 2 +- .../models/postgres/postgres_open.nim | 2 +- .../models/sqlite/sqlite_open.nim | 4 ++-- .../models/surreal/surreal_open.nim | 2 +- 14 files changed, 13 insertions(+), 97 deletions(-) diff --git a/src/allographer/v1/query_builder/libs/mariadb/mariadb_impl.nim b/src/allographer/v1/query_builder/libs/mariadb/mariadb_impl.nim index 5a150d6d..1e5a9553 100644 --- a/src/allographer/v1/query_builder/libs/mariadb/mariadb_impl.nim +++ b/src/allographer/v1/query_builder/libs/mariadb/mariadb_impl.nim @@ -9,27 +9,6 @@ import ./mariadb_rdb import ./mariadb_lib -# proc dbopen*(database: string = "", user: string = "", password: string = "", host: string = "", port: int32 = 0, maxConnections: int = 1, timeout=30): Connections = -# var pools = newSeq[Pool](maxConnections) -# for i in 0.. Date: Sun, 10 Dec 2023 12:09:52 +0000 Subject: [PATCH 2/6] fix migrate example --- example/migrate.nim | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/example/migrate.nim b/example/migrate.nim index 085886d2..39a454fa 100644 --- a/example/migrate.nim +++ b/example/migrate.nim @@ -16,7 +16,7 @@ rdb.create([ Column.string("oid2").index().nullable(), Column.string("Name").nullable(), Column.date("birth_date").nullable(), - Column.foreign("auth_id").reference("id").on("Auth").onDelete(SET_NULL).default(1) + Column.foreign("auth_id").reference("id").onTable("Auth").onDelete(SET_NULL).default(1) ]), ]) @@ -24,17 +24,18 @@ rdb.alter([ table("Users", [ # add column Column.string("aaa").default("").add(), - Column.foreign("bbb").reference("id").on("Auth").onDelete(SET_NULL).add(), + Column.foreign("bbb").reference("id").onTable("Auth").onDelete(SET_NULL).add(), # change column definition Column.string("aaa").nullable().change(), # change column name Column.renameColumn("aaa", "ccc"), # delete column - Column.deleteColumn("ccc"), - Column.deleteColumn("bbb"), + Column.dropColumn("ccc"), + Column.dropColumn("bbb"), ]), # change table name - rename("Users", "members"), - # drop table - drop("members"), + table("Users").renameTo("members"), ]) + +# drop table +rdb.drop(table("members")) From 4d0668a76659fa201e7d8520f2958a17588cd138 Mon Sep 17 00:00:00 2001 From: itsumura-h Date: Sun, 10 Dec 2023 12:50:28 +0000 Subject: [PATCH 3/6] fix --- src/allographer/v2/query_builder/models/mysql/mysql_open.nim | 2 +- tests/v1/mariadb/connection.nim | 2 +- tests/v1/mysql/connection.nim | 2 +- tests/v1/postgres/connection.nim | 2 +- tests/v1/surrealdb/connection.nim | 2 +- tests/v2/mariadb/connection.nim | 2 +- tests/v2/mysql/connection.nim | 2 +- tests/v2/postgres/connection.nim | 2 +- tests/v2/surrealdb/connection.nim | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/allographer/v2/query_builder/models/mysql/mysql_open.nim b/src/allographer/v2/query_builder/models/mysql/mysql_open.nim index 6e8d7daf..28e8185a 100644 --- a/src/allographer/v2/query_builder/models/mysql/mysql_open.nim +++ b/src/allographer/v2/query_builder/models/mysql/mysql_open.nim @@ -14,7 +14,7 @@ proc dbOpen*(_:type MySQL, database: string = "", user: string = "", password: s if conn == nil: mysql_rdb.close(conn) dbError("mysql_rdb.init() failed") - if mysql_rdb.real_connect(conn, host, user, password, database, port, nil, 0) == nil: + if mysql_rdb.real_connect(conn, host, user, password, database, port.int32, nil, 0) == nil: var errmsg = $mysql_rdb.error(conn) mysql_rdb.close(conn) dbError(errmsg) diff --git a/tests/v1/mariadb/connection.nim b/tests/v1/mariadb/connection.nim index 0c155cfd..092365c3 100644 --- a/tests/v1/mariadb/connection.nim +++ b/tests/v1/mariadb/connection.nim @@ -7,7 +7,7 @@ let user = getEnv("DB_USER") password = getEnv("DB_PASSWORD") mariadbHost = getEnv("MARIA_HOST") - mysqlPort = getEnv("MY_PORT").parseInt.int32 + mysqlPort = getEnv("MY_PORT").parseInt maxConnections = getEnv("DB_MAX_CONNECTION").parseInt timeout = getEnv("DB_TIMEOUT").parseInt diff --git a/tests/v1/mysql/connection.nim b/tests/v1/mysql/connection.nim index 87cff646..a98e307a 100644 --- a/tests/v1/mysql/connection.nim +++ b/tests/v1/mysql/connection.nim @@ -7,7 +7,7 @@ let user = getEnv("DB_USER") password = getEnv("DB_PASSWORD") mysqlHost = getEnv("MY_HOST") - mysqlPort = getEnv("MY_PORT").parseInt.int32 + mysqlPort = getEnv("MY_PORT").parseInt maxConnections = getEnv("DB_MAX_CONNECTION").parseInt timeout = getEnv("DB_TIMEOUT").parseInt diff --git a/tests/v1/postgres/connection.nim b/tests/v1/postgres/connection.nim index 4ba4016d..eba26ce7 100644 --- a/tests/v1/postgres/connection.nim +++ b/tests/v1/postgres/connection.nim @@ -7,7 +7,7 @@ let user = getEnv("DB_USER") password = getEnv("DB_PASSWORD") pgHost = getEnv("PG_HOST") - pgPort = getEnv("PG_PORT").parseInt.int32 + pgPort = getEnv("PG_PORT").parseInt maxConnections = getEnv("DB_MAX_CONNECTION").parseInt timeout = getEnv("DB_TIMEOUT").parseInt diff --git a/tests/v1/surrealdb/connection.nim b/tests/v1/surrealdb/connection.nim index b95d3219..8cae9f89 100644 --- a/tests/v1/surrealdb/connection.nim +++ b/tests/v1/surrealdb/connection.nim @@ -8,7 +8,7 @@ let user = getEnv("DB_USER") password = getEnv("DB_PASSWORD") surrealHost = getEnv("SURREAL_HOST") - surrealPort = getEnv("SURREAL_PORT").parseInt.int32 + surrealPort = getEnv("SURREAL_PORT").parseInt maxConnections = getEnv("DB_MAX_CONNECTION").parseInt timeout = getEnv("DB_TIMEOUT").parseInt diff --git a/tests/v2/mariadb/connection.nim b/tests/v2/mariadb/connection.nim index 0c155cfd..092365c3 100644 --- a/tests/v2/mariadb/connection.nim +++ b/tests/v2/mariadb/connection.nim @@ -7,7 +7,7 @@ let user = getEnv("DB_USER") password = getEnv("DB_PASSWORD") mariadbHost = getEnv("MARIA_HOST") - mysqlPort = getEnv("MY_PORT").parseInt.int32 + mysqlPort = getEnv("MY_PORT").parseInt maxConnections = getEnv("DB_MAX_CONNECTION").parseInt timeout = getEnv("DB_TIMEOUT").parseInt diff --git a/tests/v2/mysql/connection.nim b/tests/v2/mysql/connection.nim index 87cff646..a98e307a 100644 --- a/tests/v2/mysql/connection.nim +++ b/tests/v2/mysql/connection.nim @@ -7,7 +7,7 @@ let user = getEnv("DB_USER") password = getEnv("DB_PASSWORD") mysqlHost = getEnv("MY_HOST") - mysqlPort = getEnv("MY_PORT").parseInt.int32 + mysqlPort = getEnv("MY_PORT").parseInt maxConnections = getEnv("DB_MAX_CONNECTION").parseInt timeout = getEnv("DB_TIMEOUT").parseInt diff --git a/tests/v2/postgres/connection.nim b/tests/v2/postgres/connection.nim index 4ba4016d..eba26ce7 100644 --- a/tests/v2/postgres/connection.nim +++ b/tests/v2/postgres/connection.nim @@ -7,7 +7,7 @@ let user = getEnv("DB_USER") password = getEnv("DB_PASSWORD") pgHost = getEnv("PG_HOST") - pgPort = getEnv("PG_PORT").parseInt.int32 + pgPort = getEnv("PG_PORT").parseInt maxConnections = getEnv("DB_MAX_CONNECTION").parseInt timeout = getEnv("DB_TIMEOUT").parseInt diff --git a/tests/v2/surrealdb/connection.nim b/tests/v2/surrealdb/connection.nim index b95d3219..8cae9f89 100644 --- a/tests/v2/surrealdb/connection.nim +++ b/tests/v2/surrealdb/connection.nim @@ -8,7 +8,7 @@ let user = getEnv("DB_USER") password = getEnv("DB_PASSWORD") surrealHost = getEnv("SURREAL_HOST") - surrealPort = getEnv("SURREAL_PORT").parseInt.int32 + surrealPort = getEnv("SURREAL_PORT").parseInt maxConnections = getEnv("DB_MAX_CONNECTION").parseInt timeout = getEnv("DB_TIMEOUT").parseInt From 6e362dd07dabf3a0f05ca39cfd78e9ea9e0d4e5b Mon Sep 17 00:00:00 2001 From: itsumura-h Date: Sun, 10 Dec 2023 12:57:44 +0000 Subject: [PATCH 4/6] fix --- .../v1/query_builder/models/surreal/surreal_open.nim | 2 +- .../v2/query_builder/models/surreal/surreal_open.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/allographer/v1/query_builder/models/surreal/surreal_open.nim b/src/allographer/v1/query_builder/models/surreal/surreal_open.nim index 99a70bc4..fff285c8 100644 --- a/src/allographer/v1/query_builder/models/surreal/surreal_open.nim +++ b/src/allographer/v1/query_builder/models/surreal/surreal_open.nim @@ -36,7 +36,7 @@ proc dbOpen*(_:type SurrealDB, namespace:string = "", database: string = "", use let conn = SurrealConn( client: client, host: host, - port: port + port: port.int32 ) pools[i] = SurrealConnection( diff --git a/src/allographer/v2/query_builder/models/surreal/surreal_open.nim b/src/allographer/v2/query_builder/models/surreal/surreal_open.nim index 99a70bc4..fff285c8 100644 --- a/src/allographer/v2/query_builder/models/surreal/surreal_open.nim +++ b/src/allographer/v2/query_builder/models/surreal/surreal_open.nim @@ -36,7 +36,7 @@ proc dbOpen*(_:type SurrealDB, namespace:string = "", database: string = "", use let conn = SurrealConn( client: client, host: host, - port: port + port: port.int32 ) pools[i] = SurrealConnection( From 6021af7a1dedc8a8536a6f22253756377a75a9af Mon Sep 17 00:00:00 2001 From: itsumura-h Date: Sun, 10 Dec 2023 13:06:38 +0000 Subject: [PATCH 5/6] on -> onTable --- tests/test_query_paginate.nim | 2 +- tests/test_sql_injection.nim | 2 +- tests/v1/mariadb/test_query.nim | 2 +- tests/v1/mariadb/test_return_type.nim | 2 +- tests/v1/mariadb/test_schema.nim | 14 +++++++------- tests/v1/mariadb/test_transaction.nim | 2 +- tests/v1/mysql/test_query.nim | 2 +- tests/v1/mysql/test_return_type.nim | 2 +- tests/v1/mysql/test_schema.nim | 14 +++++++------- tests/v1/mysql/test_transaction.nim | 2 +- tests/v1/postgres/test_query.nim | 2 +- tests/v1/postgres/test_return_type.nim | 2 +- tests/v1/postgres/test_schema.nim | 14 +++++++------- tests/v1/postgres/test_transaction.nim | 2 +- tests/v1/sqlite/test_query.nim | 2 +- tests/v1/sqlite/test_return_type.nim | 2 +- tests/v1/sqlite/test_schema.nim | 14 +++++++------- tests/v1/sqlite/test_transaction.nim | 2 +- tests/v1/surrealdb/test_query.nim | 2 +- tests/v1/surrealdb/test_schema.nim | 8 ++++---- 20 files changed, 47 insertions(+), 47 deletions(-) diff --git a/tests/test_query_paginate.nim b/tests/test_query_paginate.nim index d6520acd..acf04bb8 100644 --- a/tests/test_query_paginate.nim +++ b/tests/test_query_paginate.nim @@ -22,7 +22,7 @@ for rdb in dbConnections: Column.string("name").nullable(), Column.string("email").nullable(), Column.string("address").nullable(), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL) + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL) ]) ]) diff --git a/tests/test_sql_injection.nim b/tests/test_sql_injection.nim index b8d0cc3a..658a2978 100644 --- a/tests/test_sql_injection.nim +++ b/tests/test_sql_injection.nim @@ -25,7 +25,7 @@ proc setUp(rdb:Rdb) = Column.string("salt").nullable(), Column.string("address").nullable(), Column.date("birth_date").nullable(), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL) + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL) ]) ) diff --git a/tests/v1/mariadb/test_query.nim b/tests/v1/mariadb/test_query.nim index 209de6d1..e717c5d7 100644 --- a/tests/v1/mariadb/test_query.nim +++ b/tests/v1/mariadb/test_query.nim @@ -27,7 +27,7 @@ proc setup(rdb:MariadbConnections) = Column.string("address").nullable(), Column.date("submit_on").nullable(), Column.datetime("submit_at").nullable(), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL).nullable() + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL).nullable() ]) ]) diff --git a/tests/v1/mariadb/test_return_type.nim b/tests/v1/mariadb/test_return_type.nim index fbb7e304..52e2b6e8 100644 --- a/tests/v1/mariadb/test_return_type.nim +++ b/tests/v1/mariadb/test_return_type.nim @@ -42,7 +42,7 @@ proc setUp(rdb:MariadbConnections) = table("user",[ Column.increments("id"), Column.string("name"), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL), + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL), Column.boolean("bool"), Column.float("float"), ]) diff --git a/tests/v1/mariadb/test_schema.nim b/tests/v1/mariadb/test_schema.nim index b46d7cb6..97140717 100644 --- a/tests/v1/mariadb/test_schema.nim +++ b/tests/v1/mariadb/test_schema.nim @@ -46,8 +46,8 @@ suite("MariaDB create table"): Column.boolean("boolean").index().default(true), Column.enumField("enumField", ["A", "B", "C"]).index().default("A"), Column.json("json").index().default(%*{"key":"value"}), - Column.foreign("int_relation_id").reference("id").on("IntRelation").onDelete(SET_NULL), - Column.strForeign("str_relation_id").reference("uuid").on("StrRelation").onDelete(SET_NULL) + Column.foreign("int_relation_id").reference("id").onTable("IntRelation").onDelete(SET_NULL), + Column.strForeign("str_relation_id").reference("uuid").onTable("StrRelation").onDelete(SET_NULL) ]), table("TypeUnique", [ Column.increments("id"), @@ -74,8 +74,8 @@ suite("MariaDB create table"): Column.boolean("boolean").unique().index().default(true), Column.enumField("enumField", ["A", "B", "C"]).unique().index().default("A"), Column.json("json").unique().index().default(%*{"key":"value"}), - Column.foreign("int_relation_id").reference("id").on("IntRelation").onDelete(SET_NULL), - Column.strForeign("str_relation_id").reference("uuid").on("StrRelation").onDelete(SET_NULL) + Column.foreign("int_relation_id").reference("id").onTable("IntRelation").onDelete(SET_NULL), + Column.strForeign("str_relation_id").reference("uuid").onTable("StrRelation").onDelete(SET_NULL) ]) ) @@ -178,8 +178,8 @@ suite($rdb & " alter table"): Column.boolean("boolean").index().default(true).add(), Column.enumField("enumField", ["A", "B", "C"]).index().default("A").add(), Column.json("json").index().default(%*{"key":"value"}).add(), - Column.foreign("int_relation_id").reference("id").on("IntRelation").onDelete(SET_NULL).add(), - Column.strForeign("str_relation_id").reference("uuid").on("StrRelation").onDelete(SET_NULL).add() + Column.foreign("int_relation_id").reference("id").onTable("IntRelation").onDelete(SET_NULL).add(), + Column.strForeign("str_relation_id").reference("uuid").onTable("StrRelation").onDelete(SET_NULL).add() ]), table("TypeUnique", [ Column.increments("id").add(), @@ -286,7 +286,7 @@ suite($rdb & " primary"): Column.integer("index1"), Column.integer("index2"), Column.string("string"), - Column.foreign("relation_id").reference("id").on("relation").onDelete(SET_NULL) + Column.foreign("relation_id").reference("id").onTable("relation").onDelete(SET_NULL) ], primary = @["index1", "index2"] ) diff --git a/tests/v1/mariadb/test_transaction.nim b/tests/v1/mariadb/test_transaction.nim index 4528891c..bcb671a1 100644 --- a/tests/v1/mariadb/test_transaction.nim +++ b/tests/v1/mariadb/test_transaction.nim @@ -24,7 +24,7 @@ proc setUp(rdb:MariadbConnections) = Column.string("name").nullable(), Column.string("email").nullable(), Column.string("address").nullable(), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL) + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL) ]) ]) diff --git a/tests/v1/mysql/test_query.nim b/tests/v1/mysql/test_query.nim index 7b30d017..069c05b1 100644 --- a/tests/v1/mysql/test_query.nim +++ b/tests/v1/mysql/test_query.nim @@ -27,7 +27,7 @@ proc setup(rdb:MysqlConnections) = Column.string("address").nullable(), Column.date("submit_on").nullable(), Column.datetime("submit_at").nullable(), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL).nullable() + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL).nullable() ]) ]) diff --git a/tests/v1/mysql/test_return_type.nim b/tests/v1/mysql/test_return_type.nim index c6b43b0f..7df4369f 100644 --- a/tests/v1/mysql/test_return_type.nim +++ b/tests/v1/mysql/test_return_type.nim @@ -42,7 +42,7 @@ proc setUp(rdb:MysqlConnections) = table("user",[ Column.increments("id"), Column.string("name"), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL), + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL), Column.boolean("bool"), Column.float("float"), ]) diff --git a/tests/v1/mysql/test_schema.nim b/tests/v1/mysql/test_schema.nim index f82cebc2..16cc495c 100644 --- a/tests/v1/mysql/test_schema.nim +++ b/tests/v1/mysql/test_schema.nim @@ -47,8 +47,8 @@ suite("MySQL create table"): Column.boolean("boolean").index().default(true), Column.enumField("enumField", ["A", "B", "C"]).index().default("A"), Column.json("json"), - Column.foreign("int_relation_id").reference("id").on("IntRelation").onDelete(SET_NULL), - Column.strForeign("str_relation_id").reference("uuid").on("StrRelation").onDelete(SET_NULL) + Column.foreign("int_relation_id").reference("id").onTable("IntRelation").onDelete(SET_NULL), + Column.strForeign("str_relation_id").reference("uuid").onTable("StrRelation").onDelete(SET_NULL) ]), # text, binary, json column can't use default value, index and unique table("TypeUnique", [ @@ -76,8 +76,8 @@ suite("MySQL create table"): Column.boolean("boolean").unique().index().default(true), Column.enumField("enumField", ["A", "B", "C"]).unique().index().default("A"), Column.json("json"), - Column.foreign("int_relation_id").reference("id").on("IntRelation").onDelete(SET_NULL), - Column.strForeign("str_relation_id").reference("uuid").on("StrRelation").onDelete(SET_NULL) + Column.foreign("int_relation_id").reference("id").onTable("IntRelation").onDelete(SET_NULL), + Column.strForeign("str_relation_id").reference("uuid").onTable("StrRelation").onDelete(SET_NULL) ]) ) @@ -487,8 +487,8 @@ suite("MySQL alter table"): Column.boolean("boolean").index().default(true).add(), Column.enumField("enumField", ["A", "B", "C"]).index().default("A").add(), Column.json("json").add(), - Column.foreign("int_relation_id").reference("id").on("IntRelation").onDelete(SET_NULL).add(), - Column.strForeign("str_relation_id").reference("uuid").on("StrRelation").onDelete(SET_NULL).add() + Column.foreign("int_relation_id").reference("id").onTable("IntRelation").onDelete(SET_NULL).add(), + Column.strForeign("str_relation_id").reference("uuid").onTable("StrRelation").onDelete(SET_NULL).add() ]), table("TypeUnique", [ Column.increments("id").add(), @@ -595,7 +595,7 @@ suite($rdb & " primary"): Column.integer("index1"), Column.integer("index2"), Column.string("string"), - Column.foreign("relation_id").reference("id").on("relation").onDelete(SET_NULL) + Column.foreign("relation_id").reference("id").onTable("relation").onDelete(SET_NULL) ], primary = @["index1", "index2"] ) diff --git a/tests/v1/mysql/test_transaction.nim b/tests/v1/mysql/test_transaction.nim index 2de728a6..6ce21cf8 100644 --- a/tests/v1/mysql/test_transaction.nim +++ b/tests/v1/mysql/test_transaction.nim @@ -24,7 +24,7 @@ proc setUp(rdb:MysqlConnections) = Column.string("name").nullable(), Column.string("email").nullable(), Column.string("address").nullable(), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL) + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL) ]) ]) diff --git a/tests/v1/postgres/test_query.nim b/tests/v1/postgres/test_query.nim index 9d1956da..d1fa977c 100644 --- a/tests/v1/postgres/test_query.nim +++ b/tests/v1/postgres/test_query.nim @@ -31,7 +31,7 @@ proc setup(rdb:PostgresConnections) = Column.string("address").nullable(), Column.date("submit_on").nullable(), Column.datetime("submit_at").nullable(), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL).nullable() + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL).nullable() ]) ]) diff --git a/tests/v1/postgres/test_return_type.nim b/tests/v1/postgres/test_return_type.nim index 62663747..76b6f6f8 100644 --- a/tests/v1/postgres/test_return_type.nim +++ b/tests/v1/postgres/test_return_type.nim @@ -42,7 +42,7 @@ proc setUp(rdb:PostgresConnections) = table("user",[ Column.increments("id"), Column.string("name"), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL), + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL), Column.boolean("bool"), Column.float("float"), ]) diff --git a/tests/v1/postgres/test_schema.nim b/tests/v1/postgres/test_schema.nim index c3f28f06..6074cb84 100644 --- a/tests/v1/postgres/test_schema.nim +++ b/tests/v1/postgres/test_schema.nim @@ -46,8 +46,8 @@ suite("PostgreSQL create table"): Column.boolean("boolean").index().default(true), Column.enumField("enumField", ["A", "B", "C"]).index().default("A"), Column.json("json").index().default(%*{"key":"value"}), - Column.foreign("int_relation_id").reference("id").on("IntRelation").onDelete(SET_NULL), - Column.strForeign("str_relation_id").reference("uuid").on("StrRelation").onDelete(SET_NULL) + Column.foreign("int_relation_id").reference("id").onTable("IntRelation").onDelete(SET_NULL), + Column.strForeign("str_relation_id").reference("uuid").onTable("StrRelation").onDelete(SET_NULL) ]), table("TypeUnique", [ Column.increments("id"), @@ -74,8 +74,8 @@ suite("PostgreSQL create table"): Column.boolean("boolean").unique().index().default(true), Column.enumField("enumField", ["A", "B", "C"]).unique().index().default("A"), Column.json("json").unique().index().default(%*{"key":"value"}), - Column.foreign("int_relation_id").reference("id").on("IntRelation").onDelete(SET_NULL), - Column.strForeign("str_relation_id").reference("uuid").on("StrRelation").onDelete(SET_NULL) + Column.foreign("int_relation_id").reference("id").onTable("IntRelation").onDelete(SET_NULL), + Column.strForeign("str_relation_id").reference("uuid").onTable("StrRelation").onDelete(SET_NULL) ]) ) @@ -178,8 +178,8 @@ suite($rdb & " alter table"): Column.boolean("boolean").index().default(true).add(), Column.enumField("enumField", ["A", "B", "C"]).index().default("A").add(), Column.json("json").index().default(%*{"key":"value"}).add(), - Column.foreign("int_relation_id").reference("id").on("IntRelation").onDelete(SET_NULL).add(), - Column.strForeign("str_relation_id").reference("uuid").on("StrRelation").onDelete(SET_NULL).add() + Column.foreign("int_relation_id").reference("id").onTable("IntRelation").onDelete(SET_NULL).add(), + Column.strForeign("str_relation_id").reference("uuid").onTable("StrRelation").onDelete(SET_NULL).add() ]), table("TypeUnique", [ Column.increments("id").add(), @@ -286,7 +286,7 @@ suite($rdb & " primary"): Column.integer("index1"), Column.integer("index2"), Column.string("string"), - Column.foreign("relation_id").reference("id").on("relation").onDelete(SET_NULL) + Column.foreign("relation_id").reference("id").onTable("relation").onDelete(SET_NULL) ], primary = @["index1", "index2"] ) diff --git a/tests/v1/postgres/test_transaction.nim b/tests/v1/postgres/test_transaction.nim index e92437d7..18091af4 100644 --- a/tests/v1/postgres/test_transaction.nim +++ b/tests/v1/postgres/test_transaction.nim @@ -24,7 +24,7 @@ proc setUp(rdb:PostgresConnections) = Column.string("name").nullable(), Column.string("email").nullable(), Column.string("address").nullable(), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL) + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL) ]) ]) diff --git a/tests/v1/sqlite/test_query.nim b/tests/v1/sqlite/test_query.nim index cc3e68cb..880b6452 100644 --- a/tests/v1/sqlite/test_query.nim +++ b/tests/v1/sqlite/test_query.nim @@ -31,7 +31,7 @@ proc setup(rdb:SqliteConnections) = Column.string("address").nullable(), Column.date("submit_on").nullable(), Column.datetime("submit_at").nullable(), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL).nullable() + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL).nullable() ]) ]) diff --git a/tests/v1/sqlite/test_return_type.nim b/tests/v1/sqlite/test_return_type.nim index b063a714..7d12f5e1 100644 --- a/tests/v1/sqlite/test_return_type.nim +++ b/tests/v1/sqlite/test_return_type.nim @@ -42,7 +42,7 @@ proc setUp(rdb:SqliteConnections) = table("user",[ Column.increments("id"), Column.string("name"), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL), + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL), Column.boolean("bool"), Column.float("float"), ]) diff --git a/tests/v1/sqlite/test_schema.nim b/tests/v1/sqlite/test_schema.nim index b2a394d2..52196086 100644 --- a/tests/v1/sqlite/test_schema.nim +++ b/tests/v1/sqlite/test_schema.nim @@ -46,8 +46,8 @@ suite("Sqlite create table"): Column.boolean("boolean").index().default(true), Column.enumField("enumField", ["A", "B", "C"]).index().default("A"), Column.json("json").index().default(%*{"key":"value"}), - Column.foreign("int_relation_id").reference("id").on("IntRelation").onDelete(SET_NULL), - Column.strForeign("str_relation_id").reference("uuid").on("StrRelation").onDelete(SET_NULL) + Column.foreign("int_relation_id").reference("id").onTable("IntRelation").onDelete(SET_NULL), + Column.strForeign("str_relation_id").reference("uuid").onTable("StrRelation").onDelete(SET_NULL) ]), table("TypeUnique", [ Column.increments("id"), @@ -74,8 +74,8 @@ suite("Sqlite create table"): Column.boolean("boolean").unique().index().default(true), Column.enumField("enumField", ["A", "B", "C"]).unique().index().default("A"), Column.json("json").unique().index().default(%*{"key":"value"}), - Column.foreign("int_relation_id").reference("id").on("IntRelation").onDelete(SET_NULL), - Column.strForeign("str_relation_id").reference("uuid").on("StrRelation").onDelete(SET_NULL) + Column.foreign("int_relation_id").reference("id").onTable("IntRelation").onDelete(SET_NULL), + Column.strForeign("str_relation_id").reference("uuid").onTable("StrRelation").onDelete(SET_NULL) ]) ) @@ -178,8 +178,8 @@ suite($rdb & " alter table"): Column.boolean("boolean").index().default(true).add(), Column.enumField("enumField", ["A", "B", "C"]).index().default("A").add(), Column.json("json").index().default(%*{"key":"value"}).add(), - Column.foreign("int_relation_id").reference("id").on("IntRelation").onDelete(SET_NULL).add(), - Column.strForeign("str_relation_id").reference("uuid").on("StrRelation").onDelete(SET_NULL).add() + Column.foreign("int_relation_id").reference("id").onTable("IntRelation").onDelete(SET_NULL).add(), + Column.strForeign("str_relation_id").reference("uuid").onTable("StrRelation").onDelete(SET_NULL).add() ]), table("TypeUnique", [ Column.increments("id").add(), @@ -286,7 +286,7 @@ suite($rdb & " primary"): Column.integer("index1"), Column.integer("index2"), Column.string("string"), - Column.foreign("relation_id").reference("id").on("relation").onDelete(SET_NULL) + Column.foreign("relation_id").reference("id").onTable("relation").onDelete(SET_NULL) ], primary = @["index1", "index2"] ) diff --git a/tests/v1/sqlite/test_transaction.nim b/tests/v1/sqlite/test_transaction.nim index f7c5e470..2f58c8e5 100644 --- a/tests/v1/sqlite/test_transaction.nim +++ b/tests/v1/sqlite/test_transaction.nim @@ -24,7 +24,7 @@ proc setUp(rdb:SqliteConnections) = Column.string("name").nullable(), Column.string("email").nullable(), Column.string("address").nullable(), - Column.foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL) + Column.foreign("auth_id").reference("id").onTable("auth").onDelete(SET_NULL) ]) ]) diff --git a/tests/v1/surrealdb/test_query.nim b/tests/v1/surrealdb/test_query.nim index 312e113b..b8580708 100644 --- a/tests/v1/surrealdb/test_query.nim +++ b/tests/v1/surrealdb/test_query.nim @@ -33,7 +33,7 @@ proc setup(rdb:SurrealConnections) = Column.string("address").nullable(), Column.date("submit_on"), Column.datetime("submit_at"), - Column.foreign("auth").reference("id").on("auth").onDelete(SET_NULL).nullable() + Column.foreign("auth").reference("id").onTable("auth").onDelete(SET_NULL).nullable() ]) ]) diff --git a/tests/v1/surrealdb/test_schema.nim b/tests/v1/surrealdb/test_schema.nim index ff500aeb..622210f9 100644 --- a/tests/v1/surrealdb/test_schema.nim +++ b/tests/v1/surrealdb/test_schema.nim @@ -43,7 +43,7 @@ suite("SurrealDB create table"): Column.boolean("boolean").index().default(true), Column.enumField("enumField", ["A", "B", "C"]).index().default("A"), Column.json("json").index().default(%*{"key":"value"}), - Column.foreign("relation").reference("id").on("relation").onDelete(SET_NULL).nullable(), + Column.foreign("relation").reference("id").onTable("relation").onDelete(SET_NULL).nullable(), ]), table("TypeUnique", [ Column.increments("index"), @@ -70,7 +70,7 @@ suite("SurrealDB create table"): Column.boolean("boolean").index().unique().unique().default(true), Column.enumField("enumField", ["A", "B", "C"]).index().unique().default("A"), Column.json("json").index().unique().default(%*{"key":"value"}), - Column.foreign("relation").reference("id").on("relation").onDelete(SET_NULL).nullable(), + Column.foreign("relation").reference("id").onTable("relation").onDelete(SET_NULL).nullable(), ]), ) @@ -313,7 +313,7 @@ suite("SurrealDB alter table"): Column.boolean("boolean").index().default(true).add(), Column.enumField("enumField", ["A", "B", "C"]).index().default("A").add(), Column.json("json").index().default(%*{"key":"value"}).add(), - Column.foreign("relation").reference("id").on("relation").onDelete(SET_NULL).nullable().add(), + Column.foreign("relation").reference("id").onTable("relation").onDelete(SET_NULL).nullable().add(), ]), table("TypeUnique", [ Column.increments("index").add(), @@ -340,7 +340,7 @@ suite("SurrealDB alter table"): Column.boolean("boolean").index().unique().unique().default(true).add(), Column.enumField("enumField", ["A", "B", "C"]).index().unique().default("A").add(), Column.json("json").index().unique().default(%*{"key":"value"}).add(), - Column.foreign("relation").reference("id").on("relation").onDelete(SET_NULL).nullable().add(), + Column.foreign("relation").reference("id").onTable("relation").onDelete(SET_NULL).nullable().add(), ]), ) From e972d746965741f50ce9c6414359ae89dd93509c Mon Sep 17 00:00:00 2001 From: itsumura-h Date: Sun, 10 Dec 2023 13:16:55 +0000 Subject: [PATCH 6/6] fix --- compose.test.yaml | 2 +- .../v1/query_builder/models/mariadb/mariadb_open.nim | 2 +- src/allographer/v1/query_builder/models/mysql/mysql_open.nim | 2 +- src/allographer/v1/schema_builder/models/column.nim | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/compose.test.yaml b/compose.test.yaml index 76e4aa18..33c05bce 100644 --- a/compose.test.yaml +++ b/compose.test.yaml @@ -5,7 +5,7 @@ services: context: . dockerfile: ./docker/ubuntu/Dockerfile args: - VERSION: 1.6.14 + VERSION: 1.6.16 tty: true volumes: - .:/root/project diff --git a/src/allographer/v1/query_builder/models/mariadb/mariadb_open.nim b/src/allographer/v1/query_builder/models/mariadb/mariadb_open.nim index fb254c2f..61225cef 100644 --- a/src/allographer/v1/query_builder/models/mariadb/mariadb_open.nim +++ b/src/allographer/v1/query_builder/models/mariadb/mariadb_open.nim @@ -14,7 +14,7 @@ proc dbOpen*(_: type MariaDB, database: string = "", user: string = "", password if conn == nil: mariadb_rdb.close(conn) dbError("mariadb_rdb.init() failed") - if mariadb_rdb.real_connect(conn, host, user, password, database, port, nil, 0) == nil: + if mariadb_rdb.real_connect(conn, host, user, password, database, port.int32, nil, 0) == nil: var errmsg = $mariadb_rdb.error(conn) mariadb_rdb.close(conn) dbError(errmsg) diff --git a/src/allographer/v1/query_builder/models/mysql/mysql_open.nim b/src/allographer/v1/query_builder/models/mysql/mysql_open.nim index 6e8d7daf..28e8185a 100644 --- a/src/allographer/v1/query_builder/models/mysql/mysql_open.nim +++ b/src/allographer/v1/query_builder/models/mysql/mysql_open.nim @@ -14,7 +14,7 @@ proc dbOpen*(_:type MySQL, database: string = "", user: string = "", password: s if conn == nil: mysql_rdb.close(conn) dbError("mysql_rdb.init() failed") - if mysql_rdb.real_connect(conn, host, user, password, database, port, nil, 0) == nil: + if mysql_rdb.real_connect(conn, host, user, password, database, port.int32, nil, 0) == nil: var errmsg = $mysql_rdb.error(conn) mysql_rdb.close(conn) dbError(errmsg) diff --git a/src/allographer/v1/schema_builder/models/column.nim b/src/allographer/v1/schema_builder/models/column.nim index 616150cd..ccecfacf 100644 --- a/src/allographer/v1/schema_builder/models/column.nim +++ b/src/allographer/v1/schema_builder/models/column.nim @@ -286,6 +286,11 @@ proc on*(self:Column, table:string):Column {.deprecated: "Use `onTable` instead return self +proc onTable*(self:Column, table:string):Column = + self.info["table"] = %*table + return self + + proc onDelete*(self:Column, kind:ForeignOnDelete):Column = self.foreignOnDelete = kind return self