Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
doc-service
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eifel邓鹏飞
doc-service
Commits
10957aa8
Commit
10957aa8
authored
Aug 23, 2024
by
Bess严根旺
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
入库
parent
7499147c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
0 deletions
+121
-0
doc_server_project.go
modes/db/doc_server_project.go
+18
-0
save_or_update.go
modes/db/project/save_or_update.go
+59
-0
mysql_db.go
modes/mysql_db.go
+44
-0
No files found.
modes/db/doc_server_project.go
0 → 100644
View file @
10957aa8
package
db
type
DocServerProject
struct
{
Id
int
`db:"id"`
ProjectName
string
`db:"project_name"`
SourceType
string
`db:"source_type"`
TargetType
string
`db:"target_type"`
SourceUrl
string
`db:"source_url"`
TargetUrl
string
`db:"target_url"`
TaskId
string
`db:"task_id"`
AppId
int
`db:"app_id"`
Status
int
`db:"status"`
CreatedAt
string
`db:"created_at"`
}
func
(
a
DocServerProject
)
TableName
()
string
{
return
"doc_server_project"
}
modes/db/project/save_or_update.go
0 → 100644
View file @
10957aa8
package
project
import
(
"doc-service/common/log"
models
"doc-service/modes"
"doc-service/modes/db"
"errors"
)
const
sqlSaveOrUpdate
=
`
insert into doc_server_project (
project_name, source_type, target_type, source_url, target_url, task_id,app_id,status,created_at
) value (
?, ?, ?, ?, ?, ?,?,?,?
)
on duplicate key update task_id = values(task_id), created_at = values(created_at)
`
// 保存或者更新数据
func
SaveOrUpdate
(
project
*
db
.
DocServerProject
)
(
error
,
int
)
{
if
nil
==
project
{
return
errors
.
New
(
"project 不能为空"
),
0
}
stmt
,
err
:=
models
.
MysqlDB
.
Prepare
(
sqlSaveOrUpdate
)
if
nil
!=
err
{
log
.
Error
(
"%+v"
,
err
)
return
err
,
0
}
result
,
err1
:=
stmt
.
Exec
(
//project.Id,
project
.
ProjectName
,
project
.
SourceType
,
project
.
TargetType
,
project
.
SourceUrl
,
project
.
TargetUrl
,
project
.
TaskId
,
project
.
AppId
,
project
.
Status
,
project
.
CreatedAt
,
)
if
nil
!=
err1
{
log
.
Error
(
"%+v"
,
err1
)
return
err1
,
0
}
rowId
,
err2
:=
result
.
LastInsertId
()
if
nil
!=
err2
{
log
.
Error
(
"%+v"
,
err2
)
return
err2
,
0
}
project
.
Id
=
int
(
rowId
)
return
nil
,
project
.
Id
}
modes/mysql_db.go
0 → 100644
View file @
10957aa8
package
models
import
(
"database/sql"
commonLog
"doc-service/common/log"
"fmt"
"gopkg.in/ini.v1"
"os"
"time"
)
import
_
"github.com/go-sql-driver/mysql"
var
MysqlDB
*
sql
.
DB
func
init
()
{
var
mysqlErr
error
config
,
iniErr
:=
ini
.
Load
(
"./conf/app.ini"
)
if
iniErr
!=
nil
{
commonLog
.
Error
(
"读取配置文件出错%s"
,
iniErr
)
os
.
Exit
(
1
)
}
ip
:=
config
.
Section
(
"mysql"
)
.
Key
(
"ip"
)
.
String
()
port
:=
config
.
Section
(
"mysql"
)
.
Key
(
"port"
)
.
String
()
user
:=
config
.
Section
(
"mysql"
)
.
Key
(
"user"
)
.
String
()
password
:=
config
.
Section
(
"mysql"
)
.
Key
(
"password"
)
.
String
()
database
:=
config
.
Section
(
"mysql"
)
.
Key
(
"database"
)
.
String
()
dsn
:=
fmt
.
Sprintf
(
"%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local"
,
user
,
password
,
ip
,
port
,
database
)
MysqlDB
,
mysqlErr
=
sql
.
Open
(
"mysql"
,
dsn
)
if
nil
!=
mysqlErr
{
panic
(
mysqlErr
)
}
MysqlDB
.
SetMaxOpenConns
(
128
)
MysqlDB
.
SetMaxIdleConns
(
16
)
MysqlDB
.
SetConnMaxLifetime
(
2
*
time
.
Minute
)
if
mysqlErr
=
MysqlDB
.
Ping
();
nil
!=
mysqlErr
{
panic
(
mysqlErr
)
}
}
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