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
8329de3c
Commit
8329de3c
authored
Oct 21, 2012
by
José Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
Missing db.Sort for PostgreSQL:
https://github.com/gosexy/db/issues/3
parent
2c99deab
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
postgresql/postgresql.go
+20
-3
20 additions, 3 deletions
postgresql/postgresql.go
postgresql/postgresql_test.go
+5
-0
5 additions, 0 deletions
postgresql/postgresql_test.go
with
25 additions
and
3 deletions
postgresql/postgresql.go
+
20
−
3
View file @
8329de3c
...
...
@@ -28,6 +28,7 @@ import (
"fmt"
"github.com/gosexy/db"
"github.com/gosexy/sugar"
"github.com/gosexy/to"
_
"github.com/xiam/gopostgresql"
"reflect"
"regexp"
...
...
@@ -36,6 +37,8 @@ import (
"time"
)
var
Debug
=
false
const
dateFormat
=
"2006-01-02 15:04:05"
const
timeFormat
=
"%d:%02d:%02d"
...
...
@@ -155,10 +158,10 @@ func (pg *PostgresqlDataSource) pgExec(method string, terms ...interface{}) (sql
q
:=
pgCompile
(
terms
)
/*
if
Debug
{
fmt
.
Printf
(
"Q: %v
\n
"
,
q
.
Query
)
fmt
.
Printf
(
"A: %v
\n
"
,
q
.
SqlArgs
)
*/
}
qs
:=
strings
.
Join
(
q
.
Query
,
" "
)
...
...
@@ -450,6 +453,7 @@ func (t *PostgresqlTable) FindAll(terms ...interface{}) []db.Item {
conditions
:=
""
limit
:=
""
offset
:=
""
sort
:=
""
// Analyzing
itop
=
len
(
terms
)
...
...
@@ -460,6 +464,19 @@ func (t *PostgresqlTable) FindAll(terms ...interface{}) []db.Item {
switch
term
.
(
type
)
{
case
db
.
Limit
:
limit
=
fmt
.
Sprintf
(
"LIMIT %v"
,
term
.
(
db
.
Limit
))
case
db
.
Sort
:
sortBy
:=
[]
string
{}
for
k
,
v
:=
range
term
.
(
db
.
Sort
)
{
v
=
strings
.
ToUpper
(
to
.
String
(
v
))
if
v
==
"-1"
{
v
=
"DESC"
}
if
v
==
"1"
{
v
=
"ASC"
}
sortBy
=
append
(
sortBy
,
fmt
.
Sprintf
(
"%s %s"
,
k
,
v
))
}
sort
=
fmt
.
Sprintf
(
"ORDER BY %s"
,
strings
.
Join
(
sortBy
,
", "
))
case
db
.
Offset
:
offset
=
fmt
.
Sprintf
(
"OFFSET %v"
,
term
.
(
db
.
Offset
))
case
db
.
Fields
:
...
...
@@ -481,7 +498,7 @@ func (t *PostgresqlTable) FindAll(terms ...interface{}) []db.Item {
"Query"
,
fmt
.
Sprintf
(
"SELECT %s FROM %s"
,
fields
,
pgTable
(
t
.
name
)),
fmt
.
Sprintf
(
"WHERE %s"
,
conditions
),
args
,
limit
,
offset
,
sort
,
limit
,
offset
,
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
postgresql/postgresql_test.go
+
5
−
0
View file @
8329de3c
...
...
@@ -15,6 +15,10 @@ const pgDatabase = "gotest"
const
pgUser
=
"gouser"
const
pgPassword
=
"gopass"
func
TestEnableDebug
(
t
*
testing
.
T
)
{
Debug
=
true
}
func
getTestData
()
db
.
Item
{
_time
,
_
:=
time
.
ParseDuration
(
"17h20m"
)
...
...
@@ -200,6 +204,7 @@ func TestPgPopulate(t *testing.T) {
people
:=
sess
.
Collection
(
"people"
)
.
FindAll
(
db
.
Fields
{
"id"
,
"name"
},
db
.
Sort
{
"name"
:
"ASC"
,
"id"
:
-
1
},
)
for
i
=
0
;
i
<
len
(
people
);
i
++
{
...
...
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