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
461dd637
Commit
461dd637
authored
Sep 21, 2012
by
José Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
Return last id.
parent
db9f10a0
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
db.go
+1
-1
1 addition, 1 deletion
db.go
mongo/mongo.go
+17
-3
17 additions, 3 deletions
mongo/mongo.go
mongo/mongo_test.go
+5
-3
5 additions, 3 deletions
mongo/mongo_test.go
mysql/mysql.go
+1
-2
1 addition, 2 deletions
mysql/mysql.go
mysql/mysql_test.go
+3
-3
3 additions, 3 deletions
mysql/mysql_test.go
with
27 additions
and
12 deletions
db.go
+
1
−
1
View file @
461dd637
...
@@ -190,7 +190,7 @@ type Database interface {
...
@@ -190,7 +190,7 @@ type Database interface {
// Collection methods.
// Collection methods.
type
Collection
interface
{
type
Collection
interface
{
Append
(
...
interface
{})
error
Append
(
...
interface
{})
([]
Id
,
error
)
Count
(
...
interface
{})
(
int
,
error
)
Count
(
...
interface
{})
(
int
,
error
)
...
...
This diff is collapsed.
Click to expand it.
mongo/mongo.go
+
17
−
3
View file @
461dd637
...
@@ -80,7 +80,11 @@ func (c *MongoDataSourceCollection) Truncate() error {
...
@@ -80,7 +80,11 @@ func (c *MongoDataSourceCollection) Truncate() error {
}
}
// Appends an item to the collection.
// Appends an item to the collection.
func
(
c
*
MongoDataSourceCollection
)
Append
(
items
...
interface
{})
error
{
func
(
c
*
MongoDataSourceCollection
)
Append
(
items
...
interface
{})
([]
db
.
Id
,
error
)
{
var
err
error
ids
:=
[]
db
.
Id
{}
parent
:=
reflect
.
TypeOf
(
c
.
collection
)
parent
:=
reflect
.
TypeOf
(
c
.
collection
)
method
,
_
:=
parent
.
MethodByName
(
"Insert"
)
method
,
_
:=
parent
.
MethodByName
(
"Insert"
)
...
@@ -91,16 +95,26 @@ func (c *MongoDataSourceCollection) Append(items ...interface{}) error {
...
@@ -91,16 +95,26 @@ func (c *MongoDataSourceCollection) Append(items ...interface{}) error {
itop
:=
len
(
items
)
itop
:=
len
(
items
)
for
i
:=
0
;
i
<
itop
;
i
++
{
for
i
:=
0
;
i
<
itop
;
i
++
{
id
:=
db
.
Id
(
bson
.
NewObjectId
()
.
Hex
())
switch
items
[
i
]
.
(
type
)
{
case
map
[
string
]
interface
{}
:
if
items
[
i
]
.
(
map
[
string
]
interface
{})[
"_id"
]
==
nil
{
items
[
i
]
.
(
map
[
string
]
interface
{})[
"_id"
]
=
id
}
}
args
[
i
+
1
]
=
reflect
.
ValueOf
(
toInternal
(
items
[
i
]))
args
[
i
+
1
]
=
reflect
.
ValueOf
(
toInternal
(
items
[
i
]))
ids
=
append
(
ids
,
id
)
}
}
exec
:=
method
.
Func
.
Call
(
args
)
exec
:=
method
.
Func
.
Call
(
args
)
if
exec
[
0
]
.
Interface
()
!=
nil
{
if
exec
[
0
]
.
Interface
()
!=
nil
{
return
exec
[
0
]
.
Interface
()
.
(
error
)
err
=
exec
[
0
]
.
Interface
()
.
(
error
)
}
}
return
nil
return
ids
,
err
}
}
// Compiles terms into something *mgo.Session can understand.
// Compiles terms into something *mgo.Session can understand.
...
...
This diff is collapsed.
Click to expand it.
mongo/mongo_test.go
+
5
−
3
View file @
461dd637
...
@@ -310,7 +310,7 @@ func TestDataTypes(t *testing.T) {
...
@@ -310,7 +310,7 @@ func TestDataTypes(t *testing.T) {
data
:=
getTestData
()
data
:=
getTestData
()
err
=
col
.
Append
(
data
)
_
,
err
=
col
.
Append
(
data
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Could not append test data."
)
t
.
Errorf
(
"Could not append test data."
)
...
@@ -320,7 +320,7 @@ func TestDataTypes(t *testing.T) {
...
@@ -320,7 +320,7 @@ func TestDataTypes(t *testing.T) {
item
:=
col
.
Find
()
item
:=
col
.
Find
()
err
=
col
.
Append
(
item
)
_
,
err
=
col
.
Append
(
item
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Errorf
(
"Expecting duplicated-key error."
)
t
.
Errorf
(
"Expecting duplicated-key error."
)
...
@@ -328,12 +328,14 @@ func TestDataTypes(t *testing.T) {
...
@@ -328,12 +328,14 @@ func TestDataTypes(t *testing.T) {
delete
(
item
,
"_id"
)
delete
(
item
,
"_id"
)
err
=
col
.
Append
(
item
)
ids
,
err
:
=
col
.
Append
(
item
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Could not append second element."
)
t
.
Errorf
(
"Could not append second element."
)
}
}
fmt
.
Printf
(
"%v
\n
"
,
ids
)
// Testing rows
// Testing rows
items
:=
col
.
FindAll
()
items
:=
col
.
FindAll
()
...
...
This diff is collapsed.
Click to expand it.
mysql/mysql.go
+
1
−
2
View file @
461dd637
...
@@ -671,7 +671,7 @@ func (t *MysqlTable) Find(terms ...interface{}) db.Item {
...
@@ -671,7 +671,7 @@ func (t *MysqlTable) Find(terms ...interface{}) db.Item {
}
}
// Inserts rows into the currently active table.
// Inserts rows into the currently active table.
func
(
t
*
MysqlTable
)
Append
(
items
...
interface
{})
error
{
func
(
t
*
MysqlTable
)
Append
(
items
...
interface
{})
([]
db
.
Id
,
error
)
{
itop
:=
len
(
items
)
itop
:=
len
(
items
)
...
@@ -684,7 +684,6 @@ func (t *MysqlTable) Append(items ...interface{}) error {
...
@@ -684,7 +684,6 @@ func (t *MysqlTable) Append(items ...interface{}) error {
for
field
,
value
:=
range
item
.
(
db
.
Item
)
{
for
field
,
value
:=
range
item
.
(
db
.
Item
)
{
fields
=
append
(
fields
,
field
)
fields
=
append
(
fields
,
field
)
//values = append(values, fmt.Sprintf("%v", value))
values
=
append
(
values
,
toInternal
(
value
))
values
=
append
(
values
,
toInternal
(
value
))
}
}
...
...
This diff is collapsed.
Click to expand it.
mysql/mysql_test.go
+
3
−
3
View file @
461dd637
...
@@ -310,7 +310,7 @@ func TestDataTypes(t *testing.T) {
...
@@ -310,7 +310,7 @@ func TestDataTypes(t *testing.T) {
data
:=
getTestData
()
data
:=
getTestData
()
err
=
col
.
Append
(
data
)
_
,
err
=
col
.
Append
(
data
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Could not append test data."
)
t
.
Errorf
(
"Could not append test data."
)
...
@@ -319,7 +319,7 @@ func TestDataTypes(t *testing.T) {
...
@@ -319,7 +319,7 @@ func TestDataTypes(t *testing.T) {
// Getting and reinserting.
// Getting and reinserting.
item
:=
col
.
Find
()
item
:=
col
.
Find
()
err
=
col
.
Append
(
item
)
_
,
err
=
col
.
Append
(
item
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Errorf
(
"Expecting duplicated-key error."
)
t
.
Errorf
(
"Expecting duplicated-key error."
)
...
@@ -327,7 +327,7 @@ func TestDataTypes(t *testing.T) {
...
@@ -327,7 +327,7 @@ func TestDataTypes(t *testing.T) {
delete
(
item
,
"id"
)
delete
(
item
,
"id"
)
err
=
col
.
Append
(
item
)
_
,
err
=
col
.
Append
(
item
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Could not append second element."
)
t
.
Errorf
(
"Could not append second element."
)
...
...
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