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
f6a00675
Commit
f6a00675
authored
Oct 21, 2012
by
José Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
Adding db.Sort support for SQLite3.
parent
1ca011e3
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
sqlite/dumps/gotest.sqlite3.db
+0
-0
0 additions, 0 deletions
sqlite/dumps/gotest.sqlite3.db
sqlite/sqlite.go
+20
-3
20 additions, 3 deletions
sqlite/sqlite.go
sqlite/sqlite_test.go
+5
-0
5 additions, 0 deletions
sqlite/sqlite_test.go
with
25 additions
and
3 deletions
sqlite/dumps/gotest.sqlite3.db
+
0
−
0
View file @
f6a00675
No preview for this file type
This diff is collapsed.
Click to expand it.
sqlite/sqlite.go
+
20
−
3
View file @
f6a00675
...
...
@@ -28,6 +28,7 @@ import (
"fmt"
"github.com/gosexy/db"
"github.com/gosexy/sugar"
"github.com/gosexy/to"
_
"github.com/xiam/gosqlite3"
"reflect"
"regexp"
...
...
@@ -36,6 +37,8 @@ import (
"time"
)
var
Debug
=
false
const
dateFormat
=
"2006-01-02 15:04:05"
const
timeFormat
=
"%d:%02d:%02d"
...
...
@@ -157,10 +160,10 @@ func (sl *SqliteDataSource) slExec(method string, terms ...interface{}) (sql.Row
q
:=
slCompile
(
terms
)
/*
if
Debug
==
true
{
fmt
.
Printf
(
"Q: %v
\n
"
,
q
.
Query
)
fmt
.
Printf
(
"A: %v
\n
"
,
q
.
SqlArgs
)
*/
}
args
:=
make
([]
reflect
.
Value
,
len
(
q
.
SqlArgs
)
+
1
)
...
...
@@ -433,6 +436,7 @@ func (t *SqliteTable) FindAll(terms ...interface{}) []db.Item {
conditions
:=
""
limit
:=
""
offset
:=
""
sort
:=
""
// Analyzing
itop
=
len
(
terms
)
...
...
@@ -443,6 +447,19 @@ func (t *SqliteTable) 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
:
...
...
@@ -464,7 +481,7 @@ func (t *SqliteTable) FindAll(terms ...interface{}) []db.Item {
"Query"
,
fmt
.
Sprintf
(
"SELECT %s FROM %s"
,
fields
,
slTable
(
t
.
name
)),
fmt
.
Sprintf
(
"WHERE %s"
,
conditions
),
args
,
limit
,
offset
,
sort
,
limit
,
offset
,
)
result
:=
t
.
slFetchAll
(
rows
)
...
...
This diff is collapsed.
Click to expand it.
sqlite/sqlite_test.go
+
5
−
0
View file @
f6a00675
...
...
@@ -54,6 +54,10 @@ func getTestData() db.Item {
return
data
}
func
TestEnableDebug
(
t
*
testing
.
T
)
{
Debug
=
true
}
func
TestSqTruncate
(
t
*
testing
.
T
)
{
sess
:=
SqliteSession
(
db
.
DataSource
{
Database
:
sqDatabase
})
...
...
@@ -195,6 +199,7 @@ func TestSqPopulate(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