Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ead63822
authored
Jul 03, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
多数据库配置
parent
3cb876c1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
15 deletions
conf/database.ini
pkg/mysql/mysql.go
test/test.go
conf/database.ini
View file @
ead63822
[gorm]
mode
=
debug
[mysql]
user_name
=
root
password
=
root
host
=
192.168.2.2
39
database
=
test
host
=
192.168.2.2
50
database
=
test
1
table_prefix
=
type
=
mysql
...
...
pkg/mysql/mysql.go
View file @
ead63822
...
...
@@ -46,12 +46,14 @@ func Setup() error {
}
DatabaseConMap
[
conName
]
.
DB
()
.
SetMaxIdleConns
(
db
.
MaxIdleCons
)
DatabaseConMap
[
conName
]
.
DB
()
.
SetMaxOpenConns
(
db
.
MaxOpenCons
)
DatabaseConMap
[
conName
]
.
LogMode
(
true
)
if
config
.
Get
(
"gorm.mode"
)
.
String
()
==
"debug"
{
DatabaseConMap
[
conName
]
.
LogMode
(
true
)
}
}
return
nil
}
func
GetDB
(
conName
string
)
*
gorm
.
DB
{
func
Connection
(
conName
string
)
*
gorm
.
DB
{
return
DatabaseConMap
[
conName
]
}
test/test.go
View file @
ead63822
...
...
@@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"search_server/boot"
"search_server/pkg/config"
"search_server/pkg/mysql"
)
...
...
@@ -15,15 +14,20 @@ func main() {
if
err
:=
boot
.
Boot
(
path
);
err
!=
nil
{
fmt
.
Println
(
err
)
}
//fmt.Println(model.GetExcludeBrandIds(1))
fmt
.
Println
(
config
.
GetSectionValues
(
"supplier_all"
))
fmt
.
Println
(
config
.
Cfg
.
Section
(
"xxx"
)
.
Key
(
"xxx"
))
res
,
_
:=
mysql
.
GetDB
(
"mysql"
)
.
Exec
(
"SELECT * FROM lie_bin"
)
.
Rows
()
fmt
.
Println
(
res
)
//client := client.
//c := course.NewCourseService("go.micro.api.jtthink.course", client)
//course_rsp, _ := c.ListForTop(context.TODO(), &course.ListRequest{Size: 10})
//fmt.Println(course_rsp.Result)
type
Result
struct
{
BinId
int
`json:"bin_id"`
Bin
string
`json:"bin"`
}
var
result
[]
Result
mysql
.
Connection
(
"bom"
)
.
Raw
(
"SELECT * FROM lie_bin"
)
.
Scan
(
&
result
)
//mysql.Connection()("bom").Table("bin").Find(&result)
fmt
.
Println
(
result
)
type
Result2
struct
{
BusinessName
string
`json:"business_name"`
}
var
result2
[]
Result2
mysql
.
Connection
(
"mysql"
)
.
Raw
(
"SELECT * FROM lie_business"
)
.
Scan
(
&
result2
)
//mysql.GetDB("bom").Table("bin").Find(&result)
fmt
.
Println
(
result2
)
}
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