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
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
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
c1d2c3ff
Commit
c1d2c3ff
authored
10 years ago
by
José Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
MySQL: Fixing visibility of result{}, table{} and source{}.
parent
de473794
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
mysql/collection.go
+9
-9
9 additions, 9 deletions
mysql/collection.go
mysql/database.go
+23
-23
23 additions, 23 deletions
mysql/database.go
mysql/result.go
+16
-16
16 additions, 16 deletions
mysql/result.go
mysql/tx.go
+6
-6
6 additions, 6 deletions
mysql/tx.go
with
54 additions
and
54 deletions
mysql/collection.go
+
9
−
9
View file @
c1d2c3ff
...
...
@@ -36,9 +36,9 @@ import (
const
defaultOperator
=
`=`
type
T
able
struct
{
type
t
able
struct
{
sqlutil
.
T
source
*
S
ource
source
*
s
ource
names
[]
string
}
...
...
@@ -176,10 +176,10 @@ func conditionValues(cond db.Cond) (columnValues sqlgen.ColumnValues, args []int
return
columnValues
,
args
}
func
(
self
*
T
able
)
Find
(
terms
...
interface
{})
db
.
Result
{
func
(
self
*
t
able
)
Find
(
terms
...
interface
{})
db
.
Result
{
where
,
arguments
:=
whereValues
(
terms
)
result
:=
&
R
esult
{
result
:=
&
r
esult
{
table
:
self
,
where
:
where
,
arguments
:
arguments
,
...
...
@@ -188,7 +188,7 @@ func (self *Table) Find(terms ...interface{}) db.Result {
return
result
}
func
(
self
*
T
able
)
tableN
(
i
int
)
string
{
func
(
self
*
t
able
)
tableN
(
i
int
)
string
{
if
len
(
self
.
names
)
>
i
{
chunks
:=
strings
.
SplitN
(
self
.
names
[
i
],
" "
,
2
)
if
len
(
chunks
)
>
0
{
...
...
@@ -199,7 +199,7 @@ func (self *Table) tableN(i int) string {
}
// Deletes all the rows within the collection.
func
(
self
*
T
able
)
Truncate
()
error
{
func
(
self
*
t
able
)
Truncate
()
error
{
_
,
err
:=
self
.
source
.
doExec
(
sqlgen
.
Statement
{
Type
:
sqlgen
.
SqlTruncate
,
...
...
@@ -214,7 +214,7 @@ func (self *Table) Truncate() error {
}
// Appends an item (map or struct) into the collection.
func
(
self
*
T
able
)
Append
(
item
interface
{})
(
interface
{},
error
)
{
func
(
self
*
t
able
)
Append
(
item
interface
{})
(
interface
{},
error
)
{
var
columns
sqlgen
.
Columns
var
values
sqlgen
.
Values
var
arguments
[]
interface
{}
...
...
@@ -262,14 +262,14 @@ func (self *Table) Append(item interface{}) (interface{}, error) {
}
// Returns true if the collection exists.
func
(
self
*
T
able
)
Exists
()
bool
{
func
(
self
*
t
able
)
Exists
()
bool
{
if
err
:=
self
.
source
.
tableExists
(
self
.
names
...
);
err
!=
nil
{
return
false
}
return
true
}
func
(
self
*
T
able
)
Name
()
string
{
func
(
self
*
t
able
)
Name
()
string
{
return
strings
.
Join
(
self
.
names
,
`, `
)
}
...
...
This diff is collapsed.
Click to expand it.
mysql/database.go
+
23
−
23
View file @
c1d2c3ff
...
...
@@ -52,7 +52,7 @@ var (
sqlPlaceholder
=
sqlgen
.
Value
{
sqlgen
.
Raw
{
`?`
}}
)
type
S
ource
struct
{
type
s
ource
struct
{
config
db
.
Settings
session
*
sql
.
DB
collections
map
[
string
]
db
.
Collection
...
...
@@ -111,10 +111,10 @@ func init() {
cache
.
NewCache
(),
}
db
.
Register
(
Adapter
,
&
S
ource
{})
db
.
Register
(
Adapter
,
&
s
ource
{})
}
func
(
self
*
S
ource
)
doExec
(
stmt
sqlgen
.
Statement
,
args
...
interface
{})
(
sql
.
Result
,
error
)
{
func
(
self
*
s
ource
)
doExec
(
stmt
sqlgen
.
Statement
,
args
...
interface
{})
(
sql
.
Result
,
error
)
{
var
query
string
var
res
sql
.
Result
var
err
error
...
...
@@ -142,7 +142,7 @@ func (self *Source) doExec(stmt sqlgen.Statement, args ...interface{}) (sql.Resu
return
res
,
err
}
func
(
self
*
S
ource
)
doQuery
(
stmt
sqlgen
.
Statement
,
args
...
interface
{})
(
*
sql
.
Rows
,
error
)
{
func
(
self
*
s
ource
)
doQuery
(
stmt
sqlgen
.
Statement
,
args
...
interface
{})
(
*
sql
.
Rows
,
error
)
{
var
rows
*
sql
.
Rows
var
query
string
var
err
error
...
...
@@ -170,7 +170,7 @@ func (self *Source) doQuery(stmt sqlgen.Statement, args ...interface{}) (*sql.Ro
return
rows
,
err
}
func
(
self
*
S
ource
)
doQueryRow
(
stmt
sqlgen
.
Statement
,
args
...
interface
{})
(
*
sql
.
Row
,
error
)
{
func
(
self
*
s
ource
)
doQueryRow
(
stmt
sqlgen
.
Statement
,
args
...
interface
{})
(
*
sql
.
Row
,
error
)
{
var
query
string
var
row
*
sql
.
Row
var
err
error
...
...
@@ -199,18 +199,18 @@ func (self *Source) doQueryRow(stmt sqlgen.Statement, args ...interface{}) (*sql
}
// Returns the string name of the database.
func
(
self
*
S
ource
)
Name
()
string
{
func
(
self
*
s
ource
)
Name
()
string
{
return
self
.
config
.
Database
}
// Ping verifies a connection to the database is still alive,
// establishing a connection if necessary.
func
(
self
*
S
ource
)
Ping
()
error
{
func
(
self
*
s
ource
)
Ping
()
error
{
return
self
.
session
.
Ping
()
}
func
(
self
*
S
ource
)
clone
()
(
*
S
ource
,
error
)
{
src
:=
&
S
ource
{}
func
(
self
*
s
ource
)
clone
()
(
*
s
ource
,
error
)
{
src
:=
&
s
ource
{}
src
.
Setup
(
self
.
config
)
if
err
:=
src
.
Open
();
err
!=
nil
{
...
...
@@ -220,13 +220,13 @@ func (self *Source) clone() (*Source, error) {
return
src
,
nil
}
func
(
self
*
S
ource
)
Clone
()
(
db
.
Database
,
error
)
{
func
(
self
*
s
ource
)
Clone
()
(
db
.
Database
,
error
)
{
return
self
.
clone
()
}
func
(
self
*
S
ource
)
Transaction
()
(
db
.
Tx
,
error
)
{
func
(
self
*
s
ource
)
Transaction
()
(
db
.
Tx
,
error
)
{
var
err
error
var
clone
*
S
ource
var
clone
*
s
ource
var
sqlTx
*
sql
.
Tx
if
sqlTx
,
err
=
self
.
session
.
Begin
();
err
!=
nil
{
...
...
@@ -237,7 +237,7 @@ func (self *Source) Transaction() (db.Tx, error) {
return
nil
,
err
}
tx
:=
&
T
x
{
clone
}
tx
:=
&
t
x
{
clone
}
clone
.
tx
=
sqlTx
...
...
@@ -245,19 +245,19 @@ func (self *Source) Transaction() (db.Tx, error) {
}
// Stores database settings.
func
(
self
*
S
ource
)
Setup
(
config
db
.
Settings
)
error
{
func
(
self
*
s
ource
)
Setup
(
config
db
.
Settings
)
error
{
self
.
config
=
config
self
.
collections
=
make
(
map
[
string
]
db
.
Collection
)
return
self
.
Open
()
}
// Returns the underlying *sql.DB instance.
func
(
self
*
S
ource
)
Driver
()
interface
{}
{
func
(
self
*
s
ource
)
Driver
()
interface
{}
{
return
self
.
session
}
// Attempts to connect to a database using the stored settings.
func
(
self
*
S
ource
)
Open
()
error
{
func
(
self
*
s
ource
)
Open
()
error
{
var
err
error
if
self
.
config
.
Host
==
""
{
...
...
@@ -300,7 +300,7 @@ func (self *Source) Open() error {
}
// Closes the current database session.
func
(
self
*
S
ource
)
Close
()
error
{
func
(
self
*
s
ource
)
Close
()
error
{
if
self
.
session
!=
nil
{
return
self
.
session
.
Close
()
}
...
...
@@ -308,13 +308,13 @@ func (self *Source) Close() error {
}
// Changes the active database.
func
(
self
*
S
ource
)
Use
(
database
string
)
error
{
func
(
self
*
s
ource
)
Use
(
database
string
)
error
{
self
.
config
.
Database
=
database
return
self
.
Open
()
}
// Drops the currently active database.
func
(
self
*
S
ource
)
Drop
()
error
{
func
(
self
*
s
ource
)
Drop
()
error
{
_
,
err
:=
self
.
doQuery
(
sqlgen
.
Statement
{
Type
:
sqlgen
.
SqlDropDatabase
,
...
...
@@ -325,7 +325,7 @@ func (self *Source) Drop() error {
}
// Returns a list of all tables within the currently active database.
func
(
self
*
S
ource
)
Collections
()
([]
string
,
error
)
{
func
(
self
*
s
ource
)
Collections
()
([]
string
,
error
)
{
var
collections
[]
string
var
collection
string
...
...
@@ -354,7 +354,7 @@ func (self *Source) Collections() ([]string, error) {
return
collections
,
nil
}
func
(
self
*
S
ource
)
tableExists
(
names
...
string
)
error
{
func
(
self
*
s
ource
)
tableExists
(
names
...
string
)
error
{
for
_
,
name
:=
range
names
{
rows
,
err
:=
self
.
doQuery
(
sqlgen
.
Statement
{
...
...
@@ -384,13 +384,13 @@ func (self *Source) tableExists(names ...string) error {
}
// Returns a collection instance by name.
func
(
self
*
S
ource
)
Collection
(
names
...
string
)
(
db
.
Collection
,
error
)
{
func
(
self
*
s
ource
)
Collection
(
names
...
string
)
(
db
.
Collection
,
error
)
{
if
len
(
names
)
==
0
{
return
nil
,
db
.
ErrMissingCollectionName
}
col
:=
&
T
able
{
col
:=
&
t
able
{
source
:
self
,
names
:
names
,
}
...
...
This diff is collapsed.
Click to expand it.
mysql/result.go
+
16
−
16
View file @
c1d2c3ff
...
...
@@ -35,8 +35,8 @@ type counter_t struct {
Total
uint64
`db:"_t"`
}
type
R
esult
struct
{
table
*
T
able
type
r
esult
struct
{
table
*
t
able
cursor
*
sql
.
Rows
// This is the main query cursor. It starts as a nil value.
limit
sqlgen
.
Limit
offset
sqlgen
.
Offset
...
...
@@ -48,7 +48,7 @@ type Result struct {
}
// Executes a SELECT statement that can feed Next(), All() or One().
func
(
self
*
R
esult
)
setCursor
()
error
{
func
(
self
*
r
esult
)
setCursor
()
error
{
var
err
error
// We need a cursor, if the cursor does not exists yet then we create one.
if
self
.
cursor
==
nil
{
...
...
@@ -67,27 +67,27 @@ func (self *Result) setCursor() error {
}
// Sets conditions for reducing the working set.
func
(
self
*
R
esult
)
Where
(
terms
...
interface
{})
db
.
Result
{
func
(
self
*
r
esult
)
Where
(
terms
...
interface
{})
db
.
Result
{
self
.
where
,
self
.
arguments
=
whereValues
(
terms
)
return
self
}
// Determines the maximum limit of results to be returned.
func
(
self
*
R
esult
)
Limit
(
n
uint
)
db
.
Result
{
func
(
self
*
r
esult
)
Limit
(
n
uint
)
db
.
Result
{
self
.
limit
=
sqlgen
.
Limit
(
n
)
return
self
}
// Determines how many documents will be skipped before starting to grab
// results.
func
(
self
*
R
esult
)
Skip
(
n
uint
)
db
.
Result
{
func
(
self
*
r
esult
)
Skip
(
n
uint
)
db
.
Result
{
self
.
offset
=
sqlgen
.
Offset
(
n
)
return
self
}
// Used to group results that have the same value in the same column or
// columns.
func
(
self
*
R
esult
)
Group
(
fields
...
interface
{})
db
.
Result
{
func
(
self
*
r
esult
)
Group
(
fields
...
interface
{})
db
.
Result
{
groupByColumns
:=
make
(
sqlgen
.
GroupBy
,
0
,
len
(
fields
))
...
...
@@ -108,7 +108,7 @@ func (self *Result) Group(fields ...interface{}) db.Result {
// Determines sorting of results according to the provided names. Fields may be
// prefixed by - (minus) which means descending order, ascending order would be
// used otherwise.
func
(
self
*
R
esult
)
Sort
(
fields
...
interface
{})
db
.
Result
{
func
(
self
*
r
esult
)
Sort
(
fields
...
interface
{})
db
.
Result
{
sortColumns
:=
make
(
sqlgen
.
SortColumns
,
0
,
len
(
fields
))
...
...
@@ -146,7 +146,7 @@ func (self *Result) Sort(fields ...interface{}) db.Result {
}
// Retrieves only the given fields.
func
(
self
*
R
esult
)
Select
(
fields
...
interface
{})
db
.
Result
{
func
(
self
*
r
esult
)
Select
(
fields
...
interface
{})
db
.
Result
{
self
.
columns
=
make
(
sqlgen
.
Columns
,
0
,
len
(
fields
))
l
:=
len
(
fields
)
...
...
@@ -163,7 +163,7 @@ func (self *Result) Select(fields ...interface{}) db.Result {
}
// Dumps all results into a pointer to an slice of structs or maps.
func
(
self
*
R
esult
)
All
(
dst
interface
{})
error
{
func
(
self
*
r
esult
)
All
(
dst
interface
{})
error
{
var
err
error
if
self
.
cursor
!=
nil
{
...
...
@@ -186,7 +186,7 @@ func (self *Result) All(dst interface{}) error {
}
// Fetches only one result from the resultset.
func
(
self
*
R
esult
)
One
(
dst
interface
{})
error
{
func
(
self
*
r
esult
)
One
(
dst
interface
{})
error
{
var
err
error
if
self
.
cursor
!=
nil
{
...
...
@@ -201,7 +201,7 @@ func (self *Result) One(dst interface{}) error {
}
// Fetches the next result from the resultset.
func
(
self
*
R
esult
)
Next
(
dst
interface
{})
error
{
func
(
self
*
r
esult
)
Next
(
dst
interface
{})
error
{
var
err
error
...
...
@@ -223,7 +223,7 @@ func (self *Result) Next(dst interface{}) error {
}
// Removes the matching items from the collection.
func
(
self
*
R
esult
)
Remove
()
error
{
func
(
self
*
r
esult
)
Remove
()
error
{
var
err
error
_
,
err
=
self
.
table
.
source
.
doExec
(
sqlgen
.
Statement
{
Type
:
sqlgen
.
SqlDelete
,
...
...
@@ -236,7 +236,7 @@ func (self *Result) Remove() error {
// Updates matching items from the collection with values of the given map or
// struct.
func
(
self
*
R
esult
)
Update
(
values
interface
{})
error
{
func
(
self
*
r
esult
)
Update
(
values
interface
{})
error
{
ff
,
vv
,
err
:=
self
.
table
.
FieldValues
(
values
,
toInternal
)
...
...
@@ -261,7 +261,7 @@ func (self *Result) Update(values interface{}) error {
}
// Closes the result set.
func
(
self
*
R
esult
)
Close
()
error
{
func
(
self
*
r
esult
)
Close
()
error
{
var
err
error
if
self
.
cursor
!=
nil
{
err
=
self
.
cursor
.
Close
()
...
...
@@ -271,7 +271,7 @@ func (self *Result) Close() error {
}
// Counts matching elements.
func
(
self
*
R
esult
)
Count
()
(
uint64
,
error
)
{
func
(
self
*
r
esult
)
Count
()
(
uint64
,
error
)
{
var
count
counter_t
rows
,
err
:=
self
.
table
.
source
.
doQuery
(
sqlgen
.
Statement
{
...
...
This diff is collapsed.
Click to expand it.
mysql/tx.go
+
6
−
6
View file @
c1d2c3ff
...
...
@@ -21,14 +21,14 @@
package
mysql
type
T
x
struct
{
*
S
ource
type
t
x
struct
{
*
s
ource
}
func
(
self
*
T
x
)
Commit
()
error
{
return
self
.
S
ource
.
tx
.
Commit
()
func
(
self
*
t
x
)
Commit
()
error
{
return
self
.
s
ource
.
tx
.
Commit
()
}
func
(
self
*
T
x
)
Rollback
()
error
{
return
self
.
S
ource
.
tx
.
Rollback
()
func
(
self
*
t
x
)
Rollback
()
error
{
return
self
.
s
ource
.
tx
.
Rollback
()
}
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