550
551
552
553
554
555
556
557
558
559
560
561
562
563
...
826
827
828
829
830
831
832
833
834
835
836
837
838
839
....
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
....
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
|
from parsav_artifact_claims as a where uid = $1::bigint and rid = $2::bigint
]];
};
artifact_load = {
params = {uint64}, sql = [[
select content, mime from parsav_artifacts where id = $1::bigint
]];
};
post_attach_ctl_ins = {
params = {uint64, uint64}, cmd=true, sql = [[
update parsav_posts set
artifacts = artifacts || $2::bigint
where id = $1::bigint and not
artifacts @> array[$2::bigint] -- prevent duplication
................................................................................
lib.pq.PQclear(res)
return pqr {0, nil}
else
return pqr {ct, res}
end
end
end
local terra row_to_post(r: &pqr, row: intptr): lib.mem.ptr(lib.store.post)
var subj: rawstring, sblen: intptr
var cvhu: rawstring, cvhlen: intptr
if r:null(row,3)
then subj = nil sblen = 0
else subj = r:string(row,3) sblen = r:len(row,3)+1
................................................................................
uid: uint64,
folder: pstring
)
var res = queries.artifact_enum_uid.exec(src,uid,folder)
if res.sz > 0 then
var m = lib.mem.heapa([lib.mem.ptr(lib.store.artifact)], res.sz)
for i=0,res.sz do
var id = res:int(uint64,i,0)
var idbuf: int8[lib.math.shorthand.maxlen]
var idlen = lib.math.shorthand.gen(id, &idbuf[0])
var desc = res:_string(i,2)
var folder = res:_string(i,3)
var mime = res:_string(i,4)
m.ptr[i] = [ lib.str.encapsulate(lib.store.artifact, {
desc = {`desc.ptr, `desc.ct + 1};
folder = {`folder.ptr, `folder.ct + 1};
mime = {`mime.ptr, `mime.ct + 1};
url = {`&idbuf[0], `idlen + 1};
}) ]
m(i).ptr.rid = id
m(i).ptr.owner = uid
end
return m
else return [lib.mem.lstptr(lib.store.artifact)].null() end
end];
artifact_load = [terra(
src: &lib.store.source,
rid: uint64
): {binblob, pstring}
var r = queries.artifact_load.exec(src,rid)
if r.sz == 0 then return binblob.null(), pstring.null() end
................................................................................
var mbin = r:bin(0,0)
var bin = lib.mem.heapa(uint8,mbin.ct)
lib.mem.cpy(bin.ptr, mbin.ptr, bin.ct)
r:free()
return bin, mime
end];
post_attach_ctl = [terra(
src: &lib.store.source,
post: uint64,
artifact: uint64,
detach: bool
): {}
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
<
<
<
<
<
<
<
<
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
...
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
....
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
....
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
|
from parsav_artifact_claims as a where uid = $1::bigint and rid = $2::bigint
]];
};
artifact_load = {
params = {uint64}, sql = [[
select content, mime from parsav_artifacts where id = $1::bigint
]];
};
artifact_folder_enum = {
params = {uint64}, sql = [[
select distinct folder from parsav_artifact_claims where
uid = $1::bigint and folder is not null
order by folder
]];
};
post_attach_ctl_ins = {
params = {uint64, uint64}, cmd=true, sql = [[
update parsav_posts set
artifacts = artifacts || $2::bigint
where id = $1::bigint and not
artifacts @> array[$2::bigint] -- prevent duplication
................................................................................
lib.pq.PQclear(res)
return pqr {0, nil}
else
return pqr {ct, res}
end
end
end
local terra row_to_artifact(res: &pqr, i: intptr): lib.mem.ptr(lib.store.artifact)
var id = res:int(uint64,i,0)
var idbuf: int8[lib.math.shorthand.maxlen]
var idlen = lib.math.shorthand.gen(id, &idbuf[0])
var desc = res:_string(i,2)
var folder = res:_string(i,3)
var mime = res:_string(i,4)
var m = [ lib.str.encapsulate(lib.store.artifact, {
desc = {`desc.ptr, `desc.ct + 1};
folder = {`folder.ptr, `folder.ct + 1};
mime = {`mime.ptr, `mime.ct + 1};
url = {`&idbuf[0], `idlen + 1};
}) ]
m.ptr.rid = id
return m
end
local terra row_to_post(r: &pqr, row: intptr): lib.mem.ptr(lib.store.post)
var subj: rawstring, sblen: intptr
var cvhu: rawstring, cvhlen: intptr
if r:null(row,3)
then subj = nil sblen = 0
else subj = r:string(row,3) sblen = r:len(row,3)+1
................................................................................
uid: uint64,
folder: pstring
)
var res = queries.artifact_enum_uid.exec(src,uid,folder)
if res.sz > 0 then
var m = lib.mem.heapa([lib.mem.ptr(lib.store.artifact)], res.sz)
for i=0,res.sz do
m.ptr[i] = row_to_artifact(&res, i)
m(i).ptr.owner = uid
end
return m
else return [lib.mem.lstptr(lib.store.artifact)].null() end
end];
artifact_fetch = [terra(
src: &lib.store.source,
uid: uint64,
rid: uint64
)
var res = queries.artifact_fetch.exec(src,uid,rid)
if res.sz > 0 then
var a = row_to_artifact(&res, 0)
a.ptr.owner = uid
res:free()
return a
end
return [lib.mem.ptr(lib.store.artifact)].null()
end];
artifact_load = [terra(
src: &lib.store.source,
rid: uint64
): {binblob, pstring}
var r = queries.artifact_load.exec(src,rid)
if r.sz == 0 then return binblob.null(), pstring.null() end
................................................................................
var mbin = r:bin(0,0)
var bin = lib.mem.heapa(uint8,mbin.ct)
lib.mem.cpy(bin.ptr, mbin.ptr, bin.ct)
r:free()
return bin, mime
end];
artifact_folder_enum = [terra(
src: &lib.store.source,
uid: uint64
)
var r = queries.artifact_folder_enum.exec(src,uid)
if r.sz == 0 then return [lib.mem.ptr(pstring)].null() end
defer r:free()
var lst = lib.mem.heapa(pstring, r.sz)
for i=0,r.sz do lst.ptr[i] = r:String(i,0) end
return lst
end];
post_attach_ctl = [terra(
src: &lib.store.source,
post: uint64,
artifact: uint64,
detach: bool
): {}
|