Amalegeni-Go >
Concurrent SQL
|
Amalegeni-Go |
|
Example 1 of concurrent SQL and Go
The complete code you write:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| type Rec struct {
Name string
Count int64
}
func Select(shard dbid) []Rec
<<
select 't_node', count(1)
from t_node
union all
select 't_tag', count(1)
from t_tag
>>
func Count(numShards int)
{{
for shard:=1;shard<numShards;shard++ {
fmt.Printf("\n=== SHARD: %d ===\n", shard)
for _,v := range Select(shard) {
fmt.Printf("%-8s %d\n", v.Name,v.Count)
}
}
return
}}
run
|
Note: no concurrency here yet!
Instructions
Prerequisites:
- you need Go
- the postgresql database is used, so go get the 'github.com/lib/pq' driver
- Grab the 'amgo' version for your system: see amalegeni-go download
Instructions:
Download and unpack the example1 zipfile that contains the above list code plus more.
First edit the 'setenv.sh', see instructions in the file.
unzip ex1.zip
cd concsql
vi setenv.sh
Now run amgo (amalegeni-go) on the count.amg file:
amgo count.amg
template/sc.tpl * count.amg
Generating: src/count/main.go
Compile/install the produced code:
go install count
Before running 'count', edit the 'conf.json' file to configure your database shards:
vi conf.json
Ok. All set to go?
count
# conf.json : 17 shards
=== SHARD: 1 ===
t_node 2123557
t_tag 7072760
=== SHARD: 2 ===
t_node 2626921
t_tag 9253770
=== SHARD: 3 ===
t_node 2708526
t_tag 9232109
..
..
| |
© Willem Moors, 2013 - 2020
|