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
b22bcb38
Commit
b22bcb38
authored
Jun 21, 2014
by
José Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
Documentation: reviewing error.go, wrapper.go y main_test.go.
parent
bdd1debc
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
error.go
+24
-26
24 additions, 26 deletions
error.go
main_test.go
+21
-0
21 additions, 0 deletions
main_test.go
wrapper.go
+34
-36
34 additions, 36 deletions
wrapper.go
with
79 additions
and
62 deletions
error.go
+
24
−
26
View file @
b22bcb38
/*
// Copyright (c) 2012-2014 José Carlos Nieto, https://menteslibres.net/xiam
Copyright (c) 2012-2014 José Carlos Nieto, https://menteslibres.net/xiam
//
// Permission is hereby granted, free of charge, to any person obtaining
Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
"Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
the following conditions:
//
// The above copyright notice and this permission notice shall be
The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package
db
package
db
...
@@ -27,7 +25,7 @@ import (
...
@@ -27,7 +25,7 @@ import (
"errors"
"errors"
)
)
//
Application
error messages.
//
Shared
error messages.
var
(
var
(
ErrExpectingPointer
=
errors
.
New
(
`Argument must be an address.`
)
ErrExpectingPointer
=
errors
.
New
(
`Argument must be an address.`
)
ErrExpectingSlicePointer
=
errors
.
New
(
`Argument must be a slice address.`
)
ErrExpectingSlicePointer
=
errors
.
New
(
`Argument must be a slice address.`
)
...
@@ -46,7 +44,7 @@ var (
...
@@ -46,7 +44,7 @@ var (
ErrUnsupported
=
errors
.
New
(
`This action is currently unsupported on this database.`
)
ErrUnsupported
=
errors
.
New
(
`This action is currently unsupported on this database.`
)
ErrQueryIsPending
=
errors
.
New
(
`Can't execute this instruction while the result set is still open.`
)
ErrQueryIsPending
=
errors
.
New
(
`Can't execute this instruction while the result set is still open.`
)
ErrUnsupportedDestination
=
errors
.
New
(
`Unsupported destination type.`
)
ErrUnsupportedDestination
=
errors
.
New
(
`Unsupported destination type.`
)
)
// Deprecated but kept for backwards compatibility. See: https://github.com/upper/db/issues/18
// Deprecated but kept for backwards compatibility. See: https://github.com/upper/db/issues/18
ErrCollectionDoesNotExists
=
ErrCollectionDoesNotExist
var
ErrCollectionDoesNotExists
=
ErrCollectionDoesNotExist
)
This diff is collapsed.
Click to expand it.
main_test.go
+
21
−
0
View file @
b22bcb38
// Copyright (c) 2012-2014 José Carlos Nieto, https://menteslibres.net/xiam
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package
db_test
package
db_test
import
(
import
(
...
...
This diff is collapsed.
Click to expand it.
wrapper.go
+
34
−
36
View file @
b22bcb38
/*
// Copyright (c) 2012-2014 José Carlos Nieto, https://menteslibres.net/xiam
Copyright (c) 2012-2014 José Carlos Nieto, https://menteslibres.net/xiam
//
// Permission is hereby granted, free of charge, to any person obtaining
Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
"Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
the following conditions:
//
// The above copyright notice and this permission notice shall be
The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package
db
package
db
...
@@ -28,34 +26,35 @@ import (
...
@@ -28,34 +26,35 @@ import (
"reflect"
"reflect"
)
)
//
R
egistered
wrapp
ers.
//
This map holds a copy of all r
egistered
adapt
ers.
var
wrappers
=
make
(
map
[
string
]
Database
)
var
wrappers
=
make
(
map
[
string
]
Database
)
// Registers a database wrapper with a unique name.
// The db.Register() function is provided for database adapters. Using
func
Register
(
name
string
,
driver
Database
)
{
// db.Register() an adapter can make itself available by the provided name.
// The adapter name must not be an empty string and the driver must not be nil,
// otherwise db.Register() will panic.
func
Register
(
name
string
,
adapter
Database
)
{
if
name
==
""
{
if
name
==
``
{
panic
(
"
Missing
wrapp
er name.
"
)
panic
(
`
Missing
adapt
er name.
`
)
}
}
if
_
,
ok
:=
wrappers
[
name
];
ok
!=
false
{
if
_
,
ok
:=
wrappers
[
name
];
ok
!=
false
{
panic
(
"
Register called twice for
driver "
+
name
)
panic
(
`db.
Register
()
called twice for
adapter: `
+
name
)
}
}
wrappers
[
name
]
=
driv
er
wrappers
[
name
]
=
adapt
er
}
}
// Configures a
connection to a database
using the
named
adapter and the given
// Configures a
database sessions
using the
given
adapter and the given
// settings.
// settings.
func
Open
(
name
string
,
settings
Settings
)
(
Database
,
error
)
{
func
Open
(
name
string
,
settings
Settings
)
(
Database
,
error
)
{
driver
,
ok
:=
wrappers
[
name
]
driver
,
ok
:=
wrappers
[
name
]
if
ok
==
false
{
if
ok
==
false
{
// Using panic instead of returning error because attemping to use an
// Using panic instead of returning error because attemping to use an
// nonexistent adapter will never result in a successful connection,
// nonexistent adapter will never result in a successful connection.
// therefore should be considered a developer's mistake and must be catched
panic
(
fmt
.
Sprintf
(
`Open: Unknown adapter %s. (see: https://upper.io/db#database-adapters)`
,
name
))
// at compilation time.
panic
(
fmt
.
Sprintf
(
"Open: Unknown adapter %s. (see: https://upper.io/db#database-adapters)"
,
name
))
}
}
// Creating a new connection everytime Open() is called.
// Creating a new connection everytime Open() is called.
...
@@ -63,8 +62,7 @@ func Open(name string, settings Settings) (Database, error) {
...
@@ -63,8 +62,7 @@ func Open(name string, settings Settings) (Database, error) {
newAdapter
:=
reflect
.
New
(
driverType
)
.
Interface
()
.
(
Database
)
newAdapter
:=
reflect
.
New
(
driverType
)
.
Interface
()
.
(
Database
)
// Setting up the connection.
// Setting up the connection.
err
:=
newAdapter
.
Setup
(
settings
)
if
err
:=
newAdapter
.
Setup
(
settings
);
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
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