good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
upper
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
open
upper
Commits
6eea5641
Commit
6eea5641
authored
11 years ago
by
José Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
Allowing simultaneous connections to different databases with the same driver.
parent
eda1364e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
db.go
+17
-4
17 additions, 4 deletions
db.go
mysql/mysql.go
+1
-0
1 addition, 0 deletions
mysql/mysql.go
mysql/mysql_test.go
+15
-0
15 additions, 0 deletions
mysql/mysql_test.go
with
33 additions
and
4 deletions
db.go
+
17
−
4
View file @
6eea5641
...
...
@@ -31,6 +31,7 @@ package db
import
(
"fmt"
"reflect"
)
/*
...
...
@@ -416,12 +417,15 @@ var wrappers = make(map[string]Database)
Registers a database wrapper with an unique name.
*/
func
Register
(
name
string
,
driver
Database
)
{
if
name
==
""
{
panic
(
"Missing wrapper name."
)
}
if
_
,
ok
:=
wrappers
[
name
];
ok
!=
false
{
panic
(
"
A wrapper with the same name was already registered."
)
panic
(
"
Register called twice for driver "
+
name
)
}
wrappers
[
name
]
=
driver
}
...
...
@@ -429,12 +433,21 @@ func Register(name string, driver Database) {
Opens a database using the named driver and the db.DataSource settings.
*/
func
Open
(
name
string
,
settings
DataSource
)
(
Database
,
error
)
{
if
_
,
ok
:=
wrappers
[
name
];
ok
==
false
{
driver
,
ok
:=
wrappers
[
name
]
if
ok
==
false
{
panic
(
fmt
.
Sprintf
(
"Unknown wrapper: %s."
,
name
))
}
err
:=
wrappers
[
name
]
.
Setup
(
settings
)
// Creating a new connection everytime Open() is called.
conn
:=
reflect
.
New
(
reflect
.
ValueOf
(
driver
)
.
Elem
()
.
Type
())
.
Interface
()
.
(
Database
)
err
:=
conn
.
Setup
(
settings
)
if
err
!=
nil
{
return
nil
,
err
}
return
wrappers
[
name
],
nil
return
conn
,
nil
}
This diff is collapsed.
Click to expand it.
mysql/mysql.go
+
1
−
0
View file @
6eea5641
...
...
@@ -179,6 +179,7 @@ func (self *Source) Close() error {
*/
func
(
self
*
Source
)
Setup
(
config
db
.
DataSource
)
error
{
self
.
config
=
config
self
.
session
=
nil
self
.
collections
=
make
(
map
[
string
]
db
.
Collection
)
return
self
.
Open
()
}
...
...
This diff is collapsed.
Click to expand it.
mysql/mysql_test.go
+
15
−
0
View file @
6eea5641
...
...
@@ -216,6 +216,21 @@ func TestFind(t *testing.T) {
defer
sess
.
Close
()
/*
// Testing simultaneous connection.
sess2, err := db.Open(wrapperName, db.DataSource {
Database: "mysql",
Socket: socket,
User: "root",
})
if err != nil {
t.Fatalf(err.Error())
}
defer sess2.Close()
*/
people
,
_
:=
sess
.
Collection
(
"people"
)
// Testing Find()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment