Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
U
ulfssar-go
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Faizal Aziz
ulfssar-go
Commits
a1fd7bf5
Commit
a1fd7bf5
authored
Jan 05, 2024
by
Faizal Aziz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change executor
parent
9a197e7c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
4 deletions
+17
-4
postgresql.go
dbcon/postgresql.go
+17
-4
No files found.
dbcon/postgresql.go
View file @
a1fd7bf5
...
...
@@ -177,7 +177,7 @@ func (d *postgresqldb) Create(args interface{}) error {
}
func
(
d
*
postgresqldb
)
CreateTable
(
tableName
string
,
structs
interface
{})
error
{
return
d
.
db
.
Create
(
generateSQLFromStorage
(
tableName
,
structs
))
.
Error
return
d
.
db
.
Exec
(
generateSQLFromStorage
(
tableName
,
structs
))
.
Error
}
func
(
d
*
postgresqldb
)
Update
(
args
interface
{})
error
{
...
...
@@ -331,6 +331,19 @@ func generateSQLFromStorage(tableName string, columnAndValues interface{}) strin
if
typeName
==
""
{
typeName
=
"text"
}
sqlDefault
:=
field
.
Tag
.
Get
(
"sql-default"
)
if
sqlDefault
!=
""
{
def
:=
"default "
+
sqlDefault
sqlDefault
=
def
}
nullable
:=
field
.
Tag
.
Get
(
"sql-nullable"
)
if
nullable
==
"true"
{
nullable
=
"not null"
}
else
{
nullable
=
""
}
argName
:=
field
.
Tag
.
Get
(
"sql-constraint"
)
keysName
:=
field
.
Tag
.
Get
(
"sql-keys"
)
...
...
@@ -347,10 +360,10 @@ func generateSQLFromStorage(tableName string, columnAndValues interface{}) strin
}
}
columnNames
+=
fmt
.
Sprintf
(
"%s %s %s %s
,"
,
columnName
,
typeNam
e
,
argName
,
keysName
)
columnNames
+=
fmt
.
Sprintf
(
"%s %s %s %s
%s %s ,"
,
columnName
,
typeName
,
sqlDefault
,
nullabl
e
,
argName
,
keysName
)
}
columnNamesStr
:=
strings
.
TrimRight
(
columnNames
,
","
)
columnNamesStr
:=
strings
.
Replace
(
strings
.
TrimRight
(
columnNames
,
","
),
"DROP DATABASE"
,
""
,
1
)
return
fmt
.
Sprintf
(
"
CREATE TABLE %s '
(%s)'"
,
tableName
,
columnNamesStr
)
return
fmt
.
Sprintf
(
"
'CREATE TABLE IF NOT EXISTS %s
(%s)'"
,
tableName
,
columnNamesStr
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment