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
d6db544a
Commit
d6db544a
authored
Dec 5, 2014
by
José Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
PostgreSQL: Adding Constraint() interface.
parent
b03f75b3
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
postgresql/collection.go
+8
-0
8 additions, 0 deletions
postgresql/collection.go
postgresql/database_test.go
+29
-4
29 additions, 4 deletions
postgresql/database_test.go
with
37 additions
and
4 deletions
postgresql/collection.go
+
8
−
0
View file @
d6db544a
...
@@ -83,6 +83,14 @@ func whereValues(term interface{}) (where sqlgen.Where, args []interface{}) {
...
@@ -83,6 +83,14 @@ func whereValues(term interface{}) (where sqlgen.Where, args []interface{}) {
for
_
,
kk
:=
range
k
{
for
_
,
kk
:=
range
k
{
where
=
append
(
where
,
kk
)
where
=
append
(
where
,
kk
)
}
}
case
db
.
Constraint
:
k
,
v
:=
conditionValues
(
t
.
Constraint
())
args
=
append
(
args
,
v
...
)
for
_
,
kk
:=
range
k
{
where
=
append
(
where
,
kk
)
}
default
:
panic
(
fmt
.
Sprintf
(
db
.
ErrUnknownConditionType
.
Error
(),
reflect
.
TypeOf
(
t
)))
}
}
return
where
,
args
return
where
,
args
...
...
This diff is collapsed.
Click to expand it.
postgresql/database_test.go
+
29
−
4
View file @
d6db544a
...
@@ -85,13 +85,21 @@ type testValuesStruct struct {
...
@@ -85,13 +85,21 @@ type testValuesStruct struct {
Time
time
.
Duration
`field:"_time"`
Time
time
.
Duration
`field:"_time"`
}
}
type
ItemWith
NonNumeric
Key
struct
{
type
ItemWithKey
struct
{
Code
string
`db:"code"`
Code
string
`db:"code"`
UserID
string
`db:"user_id"`
UserID
string
`db:"user_id"`
SomeVal
string
`db:"some_val"`
SomeVal
string
`db:"some_val"`
}
}
func
(
item
*
ItemWithNonNumericKey
)
SetID
(
keys
...
interface
{})
error
{
func
(
item
ItemWithKey
)
Constraint
()
db
.
Cond
{
cond
:=
db
.
Cond
{
"code"
:
item
.
Code
,
"user_id"
:
item
.
UserID
,
}
return
cond
}
func
(
item
*
ItemWithKey
)
SetID
(
keys
...
interface
{})
error
{
if
len
(
keys
)
==
2
{
if
len
(
keys
)
==
2
{
item
.
Code
=
string
(
keys
[
0
]
.
([]
byte
))
item
.
Code
=
string
(
keys
[
0
]
.
([]
byte
))
item
.
UserID
=
string
(
keys
[
1
]
.
([]
byte
))
item
.
UserID
=
string
(
keys
[
1
]
.
([]
byte
))
...
@@ -1336,13 +1344,13 @@ func TestNonNumericKey(t *testing.T) {
...
@@ -1336,13 +1344,13 @@ func TestNonNumericKey(t *testing.T) {
n
:=
rand
.
Intn
(
100000
)
n
:=
rand
.
Intn
(
100000
)
item
:=
&
ItemWith
NonNumeric
Key
{
item
:=
ItemWithKey
{
"ABCDEF"
,
"ABCDEF"
,
strconv
.
Itoa
(
n
),
strconv
.
Itoa
(
n
),
"Some value"
,
"Some value"
,
}
}
if
id
,
err
=
nonNumericKeys
.
Append
(
item
);
err
!=
nil
{
if
id
,
err
=
nonNumericKeys
.
Append
(
&
item
);
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -1356,6 +1364,23 @@ func TestNonNumericKey(t *testing.T) {
...
@@ -1356,6 +1364,23 @@ func TestNonNumericKey(t *testing.T) {
t
.
Fatal
(
`Keys must match.`
)
t
.
Fatal
(
`Keys must match.`
)
}
}
// Using constraint interface.
res
:=
nonNumericKeys
.
Find
(
ItemWithKey
{
Code
:
item
.
Code
,
UserID
:
item
.
UserID
})
var
item2
ItemWithKey
if
item2
.
SomeVal
==
item
.
SomeVal
{
t
.
Fatal
(
`Values must be different before query.`
)
}
if
err
:=
res
.
One
(
&
item2
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
item2
.
SomeVal
!=
item
.
SomeVal
{
t
.
Fatal
(
`Values must be equal after query.`
)
}
}
}
// Attempts to add many different datatypes to a single row in a collection,
// Attempts to add many different datatypes to a single row in a collection,
...
...
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