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
9f4086b4
Commit
9f4086b4
authored
Aug 16, 2015
by
José Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
PostgreSQL: Testing new JOIN interface.
parent
a295760f
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
postgresql/database_test.go
+79
-0
79 additions, 0 deletions
postgresql/database_test.go
postgresql/postgresql.go
+3
-0
3 additions, 0 deletions
postgresql/postgresql.go
postgresql/template.go
+30
-0
30 additions, 0 deletions
postgresql/template.go
with
112 additions
and
0 deletions
postgresql/database_test.go
+
79
−
0
View file @
9f4086b4
...
@@ -1984,4 +1984,83 @@ func TestQueryBuilder(t *testing.T) {
...
@@ -1984,4 +1984,83 @@ func TestQueryBuilder(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
// SELECT * FROM artist NATURAL JOIN publication
res
=
b
.
Select
(
"id"
)
.
From
(
"artist"
)
.
Join
(
"publication"
)
if
err
=
res
.
One
(
&
artist
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// SELECT * FROM artist a JOIN publication p ON p.author_id = a.id LIMIT 1
res
=
b
.
Select
()
.
From
(
"artist a"
)
.
Join
(
"publication p"
)
.
On
(
"p.author_id = a.id"
)
.
Limit
(
1
)
if
err
=
res
.
One
(
&
artist
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// SELECT * FROM artist a JOIN publication p ON p.author_id = a.id WHERE a.id = 2 LIMIT 1
res
=
b
.
Select
()
.
From
(
"artist a"
)
.
Join
(
"publication p"
)
.
On
(
"p.author_id = a.id"
)
.
Where
(
db
.
Cond
{
"a.id"
:
2
})
.
Limit
(
1
)
if
err
=
res
.
One
(
&
artist
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// SELECT * FROM artist a JOIN publication p ON p.author_id = a.id WHERE a.id = 2 LIMIT 1
res
=
b
.
Select
()
.
From
(
"artist a"
)
.
Join
(
"publication p"
)
.
On
(
"p.author_id = a.id"
)
.
Where
(
"a.id = ?"
,
2
)
.
Limit
(
1
)
if
err
=
res
.
One
(
&
artist
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// SELECT * FROM artist a JOIN publication p ON p.title LIKE '%Totoro%' WHERE a.id = 1
res
=
b
.
Select
()
.
From
(
"artist a"
)
.
Join
(
"publication p"
)
.
On
(
"p.title LIKE ? OR p.title LIKE ?"
,
"%Totoro%"
,
"%Robot%"
)
.
Where
(
"a.id = ?"
,
2
)
.
Limit
(
1
)
if
err
=
res
.
One
(
&
artist
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// SELECT * FROM artist a LEFT JOIN publication p1 ON (p1.id = a.id) RIGHT JOIN publication p2 ON (p2.id = a.id);
res
=
b
.
Select
()
.
From
(
"artist a"
)
.
LeftJoin
(
"publication p1"
)
.
On
(
"p1.id = a.id"
)
.
RightJoin
(
"publication p2"
)
.
On
(
"p2.id = a.id"
)
if
err
=
res
.
One
(
&
artist
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// SELECT * FROM artist CROSS JOIN publication
res
=
b
.
Select
()
.
From
(
"artist"
)
.
CrossJoin
(
"publication"
)
if
err
=
res
.
One
(
&
artist
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// SELECT * FROM artist JOIN publication USING(id)
res
=
b
.
Select
()
.
From
(
"artist"
)
.
Join
(
"publication"
)
.
Using
(
"id"
)
if
err
=
res
.
One
(
&
artist
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Should not work because using both On() and Using()
res
=
b
.
Select
()
.
From
(
"artist a"
)
.
Join
(
"publications p"
)
.
On
(
"p1.id = a.id"
)
.
Using
(
"id"
)
if
err
=
res
.
One
(
&
artist
);
err
==
nil
{
t
.
Fatal
(
"Expecting an error."
)
}
// Should not work because a Join() is missing before On().
res
=
b
.
Select
()
.
From
(
"artist a"
)
.
On
(
"p1.id = a.id"
)
if
err
=
res
.
One
(
&
artist
);
err
==
nil
{
t
.
Fatal
(
"Expecting an error."
)
}
}
}
This diff is collapsed.
Click to expand it.
postgresql/postgresql.go
+
3
−
0
View file @
9f4086b4
...
@@ -54,6 +54,9 @@ func init() {
...
@@ -54,6 +54,9 @@ func init() {
ColumnAliasLayout
:
adapterColumnAliasLayout
,
ColumnAliasLayout
:
adapterColumnAliasLayout
,
SortByColumnLayout
:
adapterSortByColumnLayout
,
SortByColumnLayout
:
adapterSortByColumnLayout
,
WhereLayout
:
adapterWhereLayout
,
WhereLayout
:
adapterWhereLayout
,
JoinLayout
:
adapterJoinLayout
,
OnLayout
:
adapterOnLayout
,
UsingLayout
:
adapterUsingLayout
,
OrderByLayout
:
adapterOrderByLayout
,
OrderByLayout
:
adapterOrderByLayout
,
InsertLayout
:
adapterInsertLayout
,
InsertLayout
:
adapterInsertLayout
,
SelectLayout
:
adapterSelectLayout
,
SelectLayout
:
adapterSelectLayout
,
...
...
This diff is collapsed.
Click to expand it.
postgresql/template.go
+
30
−
0
View file @
9f4086b4
...
@@ -53,6 +53,34 @@ const (
...
@@ -53,6 +53,34 @@ const (
{{end}}
{{end}}
`
`
adapterUsingLayout
=
`
{{if .Columns}}
USING ({{.Columns}})
{{end}}
`
adapterJoinLayout
=
`
{{if .Table}}
{{ if .On }}
{{.Type}} JOIN {{.Table}}
{{.On}}
{{ else if .Using }}
{{.Type}} JOIN {{.Table}}
{{.Using}}
{{ else if .Type | eq "CROSS" }}
{{.Type}} JOIN {{.Table}}
{{else}}
NATURAL {{.Type}} JOIN {{.Table}}
{{end}}
{{end}}
`
adapterOnLayout
=
`
{{if .Conds}}
ON {{.Conds}}
{{end}}
`
adapterSelectLayout
=
`
adapterSelectLayout
=
`
SELECT
SELECT
...
@@ -66,6 +94,8 @@ const (
...
@@ -66,6 +94,8 @@ const (
FROM {{.Table}}
FROM {{.Table}}
{{end}}
{{end}}
{{.Joins}}
{{.Where}}
{{.Where}}
{{.GroupBy}}
{{.GroupBy}}
...
...
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