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
GitLab 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
e44f6b97
Commit
e44f6b97
authored
Sep 23, 2014
by
José Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
Reviewing comments through golint.
parent
afa4908f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.go
+76
-70
76 additions, 70 deletions
main.go
with
76 additions
and
70 deletions
main.go
+
76
−
70
View file @
e44f6b97
...
...
@@ -19,9 +19,8 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// The `upper.io/db` package for Go provides a single interface for interacting
// with different data sources through the use of adapters that wrap well-known
// database drivers.
// Package db provides a single interface for interacting with different data
// sources through the use of adapters that wrap well-known database drivers.
//
// As of today, `upper.io/db` fully supports MySQL, PostgreSQL and SQLite (CRUD
// + Transactions) and provides partial support for MongoDB and QL (CRUD only).
...
...
@@ -44,8 +43,8 @@
// err = res.All(&people)
package
db
//
The `db.Cond{}` expression is
used to define conditions
u
sed
as arguments to
//
`db.Collection.Find()` and
`db.Result.Where()`.
//
Cond is a map
used to define conditions
pas
sed
to `db.Collection.Find()` and
// `db.Result.Where()`.
//
// Examples:
//
...
...
@@ -59,7 +58,7 @@ package db
// db.Cond { "age $lt": 18 }
type
Cond
map
[
string
]
interface
{}
//
The `db.Func{}` expression is used to
represent database functions.
//
Func is a struct that
represent
s
database functions.
//
// Examples:
//
...
...
@@ -79,9 +78,9 @@ type Func struct {
Args
interface
{}
}
//
The `db.And{}` expression
is used to join two or more expressions
under
// logical conjunction, it accepts `db.Cond{}`, `db.Or{}`, `db.Raw{}` and
other
// `db.And{}`
expression
s.
//
And is an array of interfaces that
is used to join two or more expressions
//
under
logical conjunction, it accepts `db.Cond{}`, `db.Or{}`, `db.Raw{}` and
//
other
`db.And{}`
value
s.
//
// Examples:
//
...
...
@@ -101,9 +100,9 @@ type Func struct {
// }
type
And
[]
interface
{}
//
The `db.Or{}` expression
is used to
glue
two or more expressions
under
// logical disjunction, it accepts `db.Cond{}`, `db.And{}`, `db.Raw{}`
and
// other `db.Or{}`
expression
s.
//
Or is an array of interfaced that
is used to
join
two or more expressions
//
under
logical disjunction, it accepts `db.Cond{}`, `db.And{}`, `db.Raw{}`
//
and
other `db.Or{}`
value
s.
//
// Example:
//
...
...
@@ -114,8 +113,8 @@ type And []interface{}
// }
type
Or
[]
interface
{}
//
The `db.Raw{}` expression is mean to
hold chunks of data to be passed to the
//
databa
se with
out any filtering
.
//
Raw
hold
s
chunks of data to be passed to the
database without any filtering.
//
U
se with
care
.
//
// When using `db.Raw{}`, the developer is responsible of providing a sanitized
// instruction to the database.
...
...
@@ -132,10 +131,10 @@ type Raw struct {
Value
interface
{}
}
//
The `db.Settings{}` struct
holds database connection and authentication
//
data. Not all fields must be supplied
, i
s
any field is skipped, the database
//
adapter will either try
to use database defaults or return an error. Refer
// to
the specific adapter to
see which fields are required.
//
Settings
holds database connection and authentication
data. Not all fields
//
are mandatory
, i
f
any field is skipped, the database
adapter will either try
// to use database defaults or return an error. Refer
to the specific adapter
// to see which fields are required.
//
// Example:
//
...
...
@@ -168,9 +167,11 @@ type Settings struct {
Charset
string
}
// The `db.Database` interface defines methods that all adapters must provide.
// Database is an interface that defines methods that must be provided by
// database adapters.
type
Database
interface
{
// Returns the underlying driver the wrapper uses. As an `interface{}`.
// Driver() Returns the underlying driver the wrapper uses. As an
// `interface{}`.
//
// In order to actually use the `interface{}` you must cast it to the known
// database driver type.
...
...
@@ -179,54 +180,54 @@ type Database interface {
// internalSQLDriver := sess.Driver().(*sql.DB)
Driver
()
interface
{}
//
A
ttempts to stablish a connection with the database server, a
previous
// call to Setup() is required.
//
Open() a
ttempts to stablish a connection with the database server, a
//
previous
call to Setup() is required.
Open
()
error
// Clones the current database session. Returns an error if the
clone could
// not be carried out.
// Clone
() duplicate
s the current database session. Returns an error if the
//
clone could
not be carried out.
Clone
()
(
Database
,
error
)
//
R
eturns error if the database server cannot be reached.
//
Ping() r
eturns error if the database server cannot be reached.
Ping
()
error
// Closes the currently active connection to the database.
// Close
() close
s the currently active connection to the database.
Close
()
error
//
R
eturns a `db.Collection{}` struct by name. Some databases
support
// collections of more than one source or table, refer to the
documentation
// of the specific database adapter to see if using multiple
sources is
// supported.
//
Collection() r
eturns a `db.Collection{}` struct by name. Some databases
//
support
collections of more than one source or table, refer to the
//
documentation
of the specific database adapter to see if using multiple
//
sources is
supported.
Collection
(
...
string
)
(
Collection
,
error
)
//
R
eturns the names of all non-system sources or tables within
the active
// database.
//
Collections() r
eturns the names of all non-system sources or tables within
//
the active
database.
Collections
()
([]
string
,
error
)
//
A
ttempts to connect to another database using the same connection
//
Use() a
ttempts to connect to another database using the same connection
// settings. Similar to MySQL's `USE` instruction.
Use
(
string
)
error
// Drops the active database.
// Drop
() drop
s the active database.
Drop
()
error
// Sets the database connection settings. In order to connect, a call
to
// `db.Database.Open()` is required.
// Set
up() set
s the database connection settings. In order to connect, a call
//
to
`db.Database.Open()` is required.
Setup
(
Settings
)
error
//
R
eturns the name of the active database.
//
Name() r
eturns the name of the active database.
Name
()
string
//
S
tarts a transaction block. Some databases do not support
transactions,
// refer to the documentation of the specific database adapter
to see the
// current status on transactions.
//
Transaction() s
tarts a transaction block. Some databases do not support
//
transactions,
refer to the documentation of the specific database adapter
//
to see the
current status on transactions.
Transaction
()
(
Tx
,
error
)
}
// T
he `db.Tx`
interface provides the same methods that the `db.Database`
does,
// plus some other that help the user deal with database transactions. In
order
// to get a proper `db.Tx` interface the `db.Database.Transaction()`
method
// must be called on an already opened database session.
// T
x is an
interface
that
provides the same methods that the `db.Database`
//
does,
plus some other that help the user deal with database transactions. In
//
order
to get a proper `db.Tx` interface the `db.Database.Transaction()`
//
method
must be called on an already opened database session.
//
// Example:
// ...
...
...
@@ -255,7 +256,7 @@ type Tx interface {
Commit
()
error
}
//
The `db.
Collection
`
interface defines methods for handling data sources or
// Collection
is an
interface
that
defines methods for handling data sources or
// tables.
type
Collection
interface
{
...
...
@@ -277,59 +278,64 @@ type Collection interface {
Name
()
string
}
//
The `db.Result`
interface defines methods for working with result sets.
//
Result is an
interface
that
defines methods for working with result sets.
type
Result
interface
{
//
D
efines the maximum number of results in this set.
//
Limit() d
efines the maximum number of results in this set.
Limit
(
uint
)
Result
// Skip
s over the *n* initial
results.
// Skip
() ignores the first *n*
results.
Skip
(
uint
)
Result
//
R
eceives fields that define the order in which elements will
be returned
// in a query, field names may be prefixed with a minus sign (-)
indicating
// descending order; ascending order would be used by default.
//
Sort() r
eceives field
name
s that define the order in which elements will
//
be returned
in a query, field names may be prefixed with a minus sign (-)
//
indicating
descending order; ascending order would be used by default.
Sort
(
...
interface
{})
Result
// Defines specific fields to be fulfilled on results in this result set.
// Select() defines specific fields to be fulfilled on results in this result
// set.
Select
(
...
interface
{})
Result
//
D
iscards the initial filtering conditions and sets new ones.
//
Where() d
iscards the initial filtering conditions and sets new ones.
Where
(
...
interface
{})
Result
//
U
sed to group results that have the same value in the same
column or
// columns.
//
Group() is u
sed to group results that have the same value in the same
//
column or
columns.
Group
(
...
interface
{})
Result
// Removes all items within the result set.
// Remove
() delete
s all items within the result set.
Remove
()
error
// Updates all items within the result set. Receives an struct or an interface{}.
// Update() modified all items within the result set. Receives an struct or
// an interface{}.
Update
(
interface
{})
error
//
R
eturns the number of items that match the set conditions (Limit
and
// Offset settings are excluded from this query).
//
Count() r
eturns the number of items that match the set conditions (Limit
//
and
Offset settings are excluded from this query).
Count
()
(
uint64
,
error
)
//
F
etches the next result within the result set and dumps it into the
given
// pointer to struct or pointer to map. You must manually call Close()
after
// finishing using Next().
//
Next() f
etches the next result within the result set and dumps it into the
//
given
pointer to struct or pointer to map. You must manually call Close()
//
after
finishing using Next().
Next
(
interface
{})
error
//
F
etches the first result within the result set and dumps it into the
given
// pointer to struct or pointer to map. Then it calls Close() to free
the
// result set.
//
One() f
etches the first result within the result set and dumps it into the
//
given
pointer to struct or pointer to map. Then it calls Close() to free
//
the
result set.
One
(
interface
{})
error
//
F
etches all results within the result set and dumps them into the
given
// pointer to slice of maps or structs. Then it calls Close() to free
the
// result set.
//
All() f
etches all results within the result set and dumps them into the
//
given
pointer to slice of maps or structs. Then it calls Close() to free
//
the
result set.
All
(
interface
{})
error
// Closes the result set.
// Close
() close
s the result set.
Close
()
error
}
// EnvEnableDebug may be used by adapters to determine if the user has enabled
// debugging.
//
// If the user sets the `UPPERIO_DB_DEBUG` environment variable to a
// non-empty value, all generated statements will be printed at runtime to
// the standard logger.
...
...
@@ -339,4 +345,4 @@ type Result interface {
// UPPERIO_DB_DEBUG=1 go test
//
// UPPERIO_DB_DEBUG=1 ./go-program
var
EnvEnableDebug
=
`UPPERIO_DB_DEBUG`
const
EnvEnableDebug
=
`UPPERIO_DB_DEBUG`
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