Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

264 fix int32 arg in dbopen #265

Merged
merged 6 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compose.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
context: .
dockerfile: ./docker/ubuntu/Dockerfile
args:
VERSION: 1.6.14
VERSION: 1.6.16
tty: true
volumes:
- .:/root/project
Expand Down
15 changes: 8 additions & 7 deletions example/migrate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@ 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)
]),
])

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"))
21 changes: 0 additions & 21 deletions src/allographer/v1/query_builder/libs/mariadb/mariadb_impl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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..<maxConnections:
# var res = mariadb_rdb.init(nil)
# if res == nil:
# dbError("could not open database connection")
# if mariadb_rdb.realConnect(res, host, user, password, database, port, nil, 0) == nil:
# var errmsg = $mariadb_rdb.error(res)
# mariadb_rdb.close(res)
# dbError(errmsg)
# pools[i] = Pool(
# mariadbConn: res,
# isBusy: false,
# createdAt: getTime().toUnix(),
# )
# result = Connections(
# pools: pools,
# timeout: timeout
# )


proc rawExec(conn:PMySQL, query: string, args: seq[string]) =
assert conn.ping == 0

Expand Down
21 changes: 0 additions & 21 deletions src/allographer/v1/query_builder/libs/mysql/mysql_impl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,6 @@ import ./mysql_rdb
import ./mysql_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..<maxConnections:
# var res = mysql_rdb.init(nil)
# if res == nil:
# dbError("could not open database connection")
# if mysql_rdb.realConnect(res, host, user, password, database, port, nil, 0) == nil:
# var errmsg = $mysql_rdb.error(res)
# mysql_rdb.close(res)
# dbError(errmsg)
# pools[i] = Pool(
# mysqlConn: res,
# isBusy: false,
# createdAt: getTime().toUnix(),
# )
# result = Connections(
# pools: pools,
# timeout: timeout
# )


proc rawExec(conn:PMySQL, query: string, args: seq[string]) =
assert conn.ping == 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import ./mariadb_types


proc dbOpen*(_: type MariaDB, database: string = "", user: string = "", password: string = "",
host: string = "", port: int32 = 0, maxConnections: int = 1, timeout=30,
host: string = "", port: int = 0, maxConnections: int = 1, timeout=30,
shouldDisplayLog=false, shouldOutputLogFile=false, logDir=""): MariadbConnections =
var pools = newSeq[MariadbConnection](maxConnections)
for i in 0..<maxConnections:
let conn = mariadb_rdb.init(nil)
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)
Expand Down
4 changes: 2 additions & 2 deletions src/allographer/v1/query_builder/models/mysql/mysql_open.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import ./mysql_types


proc dbOpen*(_:type MySQL, database: string = "", user: string = "", password: string = "",
host: string = "", port: int32 = 0, maxConnections: int = 1, timeout=30,
host: string = "", port: int = 0, maxConnections: int = 1, timeout=30,
shouldDisplayLog=false, shouldOutputLogFile=false, logDir=""): MysqlConnections =
var pools = newSeq[MysqlConnection](maxConnections)
for i in 0..<maxConnections:
let conn = mysql_rdb.init(nil)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ./postgres_types


proc dbOpen*(_:type PostgreSQL, database: string = "", user: string = "", password: string = "",
host: string = "", port: int32 = 0, maxConnections: int = 1, timeout=30,
host: string = "", port: int = 0, maxConnections: int = 1, timeout=30,
shouldDisplayLog=false, shouldOutputLogFile=false, logDir=""): PostgresConnections =
var pools = newSeq[PostgresConnection](maxConnections)
for i in 0..<maxConnections:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import ../../log
import ./sqlite_types


proc dbOpen*(_:type SQLite3, database: string = "", user: string = "", password: string = "",
host: string = "", port: int32 = 0, maxConnections: int = 1, timeout=30,
proc dbOpen*(_:type SQLite3, database: string = "",
maxConnections: int = 1, timeout=30,
shouldDisplayLog=false, shouldOutputLogFile=false, logDir=""): SqliteConnections =
var pools = newSeq[SqliteConnection](maxConnections)
for i in 0..<maxConnections:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ./surreal_types


proc dbOpen*(_:type SurrealDB, namespace:string = "", database: string = "", user: string = "", password: string = "",
host: string = "", port: int32 = 0, maxConnections: int = 1, timeout=30,
host: string = "", port: int = 0, maxConnections: int = 1, timeout=30,
shouldDisplayLog=false, shouldOutputLogFile=false, logDir=""): Future[SurrealConnections] {.async.} =
var pools = newSeq[SurrealConnection](maxConnections)
for i in 0..<maxConnections:
Expand All @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions src/allographer/v1/schema_builder/models/column.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 0 additions & 21 deletions src/allographer/v2/query_builder/libs/mariadb/mariadb_impl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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..<maxConnections:
# var res = mariadb_rdb.init(nil)
# if res == nil:
# dbError("could not open database connection")
# if mariadb_rdb.realConnect(res, host, user, password, database, port, nil, 0) == nil:
# var errmsg = $mariadb_rdb.error(res)
# mariadb_rdb.close(res)
# dbError(errmsg)
# pools[i] = Pool(
# mariadbConn: res,
# isBusy: false,
# createdAt: getTime().toUnix(),
# )
# result = Connections(
# pools: pools,
# timeout: timeout
# )


proc rawExec(conn:PMySQL, query: string, args: seq[string]) =
assert conn.ping == 0

Expand Down
21 changes: 0 additions & 21 deletions src/allographer/v2/query_builder/libs/mysql/mysql_impl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,6 @@ import ./mysql_rdb
import ./mysql_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..<maxConnections:
# var res = mysql_rdb.init(nil)
# if res == nil:
# dbError("could not open database connection")
# if mysql_rdb.realConnect(res, host, user, password, database, port, nil, 0) == nil:
# var errmsg = $mysql_rdb.error(res)
# mysql_rdb.close(res)
# dbError(errmsg)
# pools[i] = Pool(
# mysqlConn: res,
# isBusy: false,
# createdAt: getTime().toUnix(),
# )
# result = Connections(
# pools: pools,
# timeout: timeout
# )


proc rawExec(conn:PMySQL, query: string, args: seq[string]) =
assert conn.ping == 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import ./mariadb_types


proc dbOpen*(_: type MariaDB, database: string = "", user: string = "", password: string = "",
host: string = "", port: int32 = 0, maxConnections: int = 1, timeout=30,
host: string = "", port: int = 0, maxConnections: int = 1, timeout=30,
shouldDisplayLog=false, shouldOutputLogFile=false, logDir=""): MariadbConnections =
var pools = newSeq[MariadbConnection](maxConnections)
for i in 0..<maxConnections:
let conn = mariadb_rdb.init(nil)
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)
Expand Down
4 changes: 2 additions & 2 deletions src/allographer/v2/query_builder/models/mysql/mysql_open.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import ./mysql_types


proc dbOpen*(_:type MySQL, database: string = "", user: string = "", password: string = "",
host: string = "", port: int32 = 0, maxConnections: int = 1, timeout=30,
host: string = "", port: int = 0, maxConnections: int = 1, timeout=30,
shouldDisplayLog=false, shouldOutputLogFile=false, logDir=""): MysqlConnections =
var pools = newSeq[MysqlConnection](maxConnections)
for i in 0..<maxConnections:
let conn = mysql_rdb.init(nil)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ./postgres_types


proc dbOpen*(_:type PostgreSQL, database: string = "", user: string = "", password: string = "",
host: string = "", port: int32 = 0, maxConnections: int = 1, timeout=30,
host: string = "", port:int = 0, maxConnections: int = 1, timeout=30,
shouldDisplayLog=false, shouldOutputLogFile=false, logDir=""): PostgresConnections =
var pools = newSeq[PostgresConnection](maxConnections)
for i in 0..<maxConnections:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import ../../log
import ./sqlite_types


proc dbOpen*(_:type SQLite3, database: string = "", user: string = "", password: string = "",
host: string = "", port: int32 = 0, maxConnections: int = 1, timeout=30,
proc dbOpen*(_:type SQLite3, database: string = "",
maxConnections: int = 1, timeout=30,
shouldDisplayLog=false, shouldOutputLogFile=false, logDir=""): SqliteConnections =
var pools = newSeq[SqliteConnection](maxConnections)
for i in 0..<maxConnections:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ./surreal_types


proc dbOpen*(_:type SurrealDB, namespace:string = "", database: string = "", user: string = "", password: string = "",
host: string = "", port: int32 = 0, maxConnections: int = 1, timeout=30,
host: string = "", port: int = 0, maxConnections: int = 1, timeout=30,
shouldDisplayLog=false, shouldOutputLogFile=false, logDir=""): Future[SurrealConnections] {.async.} =
var pools = newSeq[SurrealConnection](maxConnections)
for i in 0..<maxConnections:
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_query_paginate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
])
])

Expand Down
2 changes: 1 addition & 1 deletion tests/test_sql_injection.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
])
)

Expand Down
2 changes: 1 addition & 1 deletion tests/v1/mariadb/connection.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/v1/mariadb/test_query.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
])
])

Expand Down
2 changes: 1 addition & 1 deletion tests/v1/mariadb/test_return_type.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
])
Expand Down
Loading