Skip to content

Commit

Permalink
iddb.rho: add readOnly facet
Browse files Browse the repository at this point in the history
fixes: #32
  • Loading branch information
dckc committed Jul 17, 2020
1 parent 7f06854 commit c1d638a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
4 changes: 2 additions & 2 deletions rchat/chain_replica.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ function notice_as_rho({ op, table_name, OLD = undefined, NEW = undefined}) {
// KLUDGE: replacing null with Nil in string form has false positives
const lit = val => val ? JSON.stringify(val).replace(/\bnull\b/g, 'Nil') : 'Nil';

// ISSUE: sync "zulip_iddb3" with myzulipdb.rho
// ISSUE: sync "zulip_iddb4" with myzulipdb.rho
return `new deployerId(\`rho:rchain:deployerId\`) in {
for(db <<- @{[*deployerId, "zulip_iddb3"]}) {
for(db <<- @{[*deployerId, "zulip_iddb4"]}) {
// ISSUE: Nil return channel: no sync
db!(${lit(op)}, ${lit(table_name)}, ${lit(OLD)}, ${lit(NEW)}, Nil)
}
Expand Down
53 changes: 45 additions & 8 deletions rchat/iddb.rho
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ in {
}
|
contract IdDB(return) = {
new self, tablesCh in {
return!(*self) |
new self, readOnly, tablesCh in {
return!(*self, *readOnly) |

contract self(@"readOnly", return) = { return!(*readOnly) } |

tablesCh!({}) | // table_name -> channel with Set of keys
// rows are stored at @{[self, table_name, key]}
Expand All @@ -37,7 +39,13 @@ in {
} |
// TODO: drop table: delete from map @tablesCh; consume keysCh, all rows

contract self(@"keys", @table_name /\ String, return) = {
contract readOnly(@"tables", return) = {
for (@tables <<- tablesCh) {
return!(tables)
}
} |

contract readOnly(@"keys", @table_name /\ String, return) = {
for (@tables <<- tablesCh) {
match tables.get(table_name) {
Nil => { return!((false, "no such table")) }
Expand All @@ -50,8 +58,37 @@ in {
}
}
} |
// TODO: select method to get record from table_name, key
// TODO: move keys, select to read-only facet

contract readOnly(@"select", @table_name /\ String, @wanted /\ List, return) = {
for (@tables <<- tablesCh) {
match tables.get(table_name) {
Nil => { return!((false, "no such table")) }
{*keysCh} => {
for (@keys <<- keysCh) {
log!({"select: keys for": table_name, "qty": keys.size()}) |
new loop in {
loop!(wanted, {}) |
contract loop(@todo, @acc) = {
match todo {
[] => return!((true, acc))
[target, ...rest] => {
if (keys.contains(target)) {
for (@record <<- @{[*self, table_name, target]}) {
loop!(rest, acc.put(target, record))
}
} else {
// TODO: warn?
loop!(rest, acc)
}
}
}
}
}
}
}
}
}
} |

contract self(@"INSERT", @table_name /\ String, _OLD, @NEW, return) = {
for (@tables <<- tablesCh) {
Expand Down Expand Up @@ -133,12 +170,12 @@ in {
// testing
new ch, logKeys in {
IdDB!(*ch) |
for (db1 <- ch) {
log!({"db1": *db1}) |
for (db1, ro1 <- ch) {
log!({"db1": *db1, "readOnly": *ro1}) |
contract logKeys(@label, @key) = {
new keysCh in {
log!({label: key}) |
db1!("keys", "player", *keysCh) |
ro1!("keys", "player", *keysCh) |
for (@{(true, keys)} <- keysCh) {
log!({label: key, "keys": keys})
}
Expand Down
16 changes: 12 additions & 4 deletions rchat/myzulipdb.rho
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ new
deployId, //(`rho:rchain:deployId`),
deployerId, //(`rho:rchain:deployerId`),
lookup(`rho:registry:lookup`),
insertArbitrary(`rho:registry:insertArbitrary`),
IdDBCh,
log(`rho:io:stderr`)
in {
lookup!(`rho:id:ka9r5c1ha5fk7y8qwgqjmhcfrm53pz1kxjq4of9qm1mhbt8dsgzp3r`, *IdDBCh) |
lookup!(`rho:id:FIXME` /* ISSUE: how to sync IdDB registry URI? */, *IdDBCh) |
for (IdDB <- IdDBCh) {
log!({"IdDB": *IdDB}) |
new dbCh in {
IdDB!(*dbCh) |
for (db <- dbCh) {
log!({"db": *db}) |
for (db, readOnly <- dbCh) {
log!({"db": *db, "readOnly": *readOnly}) |
new uriCh in {
insertArbitrary!(*readOnly, *uriCh)|
for (@uri <- uriCh) {
log!({"db readOnly facet registered at": uri})
}
} |
db!("create_table", "zerver_message", Nil) |
db!("create_table", "zerver_usermessage", Nil) |
@{[*deployerId, "zulip_iddb3"]}!(*db)
// ISSUE: sync zulip_iddb4 with chain_replica.js
@{[*deployerId, "zulip_iddb4"]}!(*db)
}
}
}
Expand Down

0 comments on commit c1d638a

Please sign in to comment.