Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
13e2d54e
Commit
13e2d54e
authored
Jan 03, 2019
by
vipwzw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add join table
parent
0f5cb91c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
1 deletion
+88
-1
runtime.js
plugin/dapp/js/executor/runtime.js
+30
-0
table.go
plugin/dapp/js/executor/table.go
+58
-1
No files found.
plugin/dapp/js/executor/runtime.js
View file @
13e2d54e
...
...
@@ -52,6 +52,36 @@ table.prototype.close = function() {
return
ret
.
err
}
function
JoinTable
(
lefttable
,
righttable
,
index
)
{
if
(
this
.
lefttable
.
kvc
!=
this
.
righttable
.
kvc
)
{
throw
new
Error
(
"the kvc of left and right must same"
)
}
this
.
lefttable
=
lefttable
this
.
righttable
=
righttable
this
.
index
=
index
var
ret
=
new_join_table
(
this
.
lefttable
.
id
,
this
.
righttable
.
id
,
index
)
if
(
ret
.
err
)
{
throw
new
Error
(
ret
.
err
)
}
this
.
id
=
ret
.
id
this
.
kvc
=
this
.
lefttable
.
kvc
}
JoinTable
.
prototype
.
Save
=
function
()
{
var
ret
=
table_save
(
this
.
id
)
if
(
!
this
.
kvc
)
{
this
.
kvc
.
save
(
ret
)
}
return
ret
}
JoinTable
.
prototype
.
close
=
function
()
{
table_close
(
this
.
lefttable
.
id
)
table_close
(
this
.
righttable
.
id
)
var
ret
=
table_close
(
this
.
id
)
return
ret
.
err
}
//account warp
function
account
(
kvc
,
execer
,
symbol
)
{
this
.
execer
=
execer
...
...
plugin/dapp/js/executor/table.go
View file @
13e2d54e
...
...
@@ -3,6 +3,7 @@ package executor
import
(
"encoding/json"
"fmt"
"strings"
"sync"
"sync/atomic"
...
...
@@ -120,12 +121,20 @@ func getTable(id int64) (*table.Table, error) {
return
nil
,
types
.
ErrNotFound
}
func
getSaver
(
id
int64
)
(
saver
,
error
)
{
if
value
,
ok
:=
globalTableHandle
.
Load
(
id
);
ok
{
return
value
.
(
saver
),
nil
}
return
nil
,
types
.
ErrNotFound
}
func
registerTableFunc
(
vm
*
otto
.
Otto
)
{
tableAddFunc
(
vm
)
tableReplaceFunc
(
vm
)
tableDelFunc
(
vm
)
tableCloseFunc
(
vm
)
tableSave
(
vm
)
tableJoinFunc
(
vm
)
}
func
tableAddFunc
(
vm
*
otto
.
Otto
)
{
...
...
@@ -194,13 +203,17 @@ func tableDelFunc(vm *otto.Otto) {
})
}
type
saver
interface
{
Save
()
(
kvs
[]
*
types
.
KeyValue
,
err
error
)
}
func
tableSave
(
vm
*
otto
.
Otto
)
{
vm
.
Set
(
"table_save"
,
func
(
call
otto
.
FunctionCall
)
otto
.
Value
{
id
,
err
:=
call
.
Argument
(
0
)
.
ToInteger
()
if
err
!=
nil
{
return
errReturn
(
vm
,
err
)
}
tab
,
err
:=
get
Table
(
id
)
tab
,
err
:=
get
Saver
(
id
)
if
err
!=
nil
{
return
errReturn
(
vm
,
err
)
}
...
...
@@ -226,6 +239,49 @@ func tableCloseFunc(vm *otto.Otto) {
})
}
func
tableJoinFunc
(
vm
*
otto
.
Otto
)
{
vm
.
Set
(
"new_join_table"
,
func
(
call
otto
.
FunctionCall
)
otto
.
Value
{
left
,
err
:=
call
.
Argument
(
0
)
.
ToInteger
()
if
err
!=
nil
{
return
errReturn
(
vm
,
err
)
}
lefttab
,
err
:=
getTable
(
left
)
if
err
!=
nil
{
return
errReturn
(
vm
,
err
)
}
right
,
err
:=
call
.
Argument
(
1
)
.
ToInteger
()
if
err
!=
nil
{
return
errReturn
(
vm
,
err
)
}
righttab
,
err
:=
getTable
(
right
)
if
err
!=
nil
{
return
errReturn
(
vm
,
err
)
}
index
,
err
:=
call
.
Argument
(
2
)
.
ToString
()
if
err
!=
nil
{
return
errReturn
(
vm
,
err
)
}
join
,
err
:=
table
.
NewJoinTable
(
lefttab
,
righttab
,
strings
.
Split
(
index
,
","
))
if
err
!=
nil
{
return
errReturn
(
vm
,
err
)
}
var
id
int64
for
{
id
=
atomic
.
AddInt64
(
&
globalHanldeID
,
1
)
%
maxjsint
if
_
,
ok
:=
globalTableHandle
.
Load
(
id
);
ok
{
continue
}
if
id
<
0
{
atomic
.
StoreInt64
(
&
globalHanldeID
,
0
)
continue
}
break
}
globalTableHandle
.
Store
(
id
,
join
)
return
newObject
(
vm
)
.
setValue
(
"id"
,
id
)
.
value
()
})
}
/*
table
要开发一个适合json的table, row 就是一个 js object
...
...
@@ -235,6 +291,7 @@ table_replace(handle, row)
table_del(handle, row)
table_save(handle)
table_close(handle)
handle := new_join_table(left, right, listofjoinindex)
*/
//join table 的操作(接口完全相同)
//handle3 := new_table(newcofifg{config1, config2})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment