Skip to content

Instantly share code, notes, and snippets.

@hkasera
Last active October 19, 2017 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkasera/5d2005368e385cf2c95b200aa71b6fbd to your computer and use it in GitHub Desktop.
Save hkasera/5d2005368e385cf2c95b200aa71b6fbd to your computer and use it in GitHub Desktop.
RPC example
table peers : { A : client, B : channel ( string ) , C : string}
PRIMARY KEY A
table random : {C : string}
sequence seq
fun increment a = nextval seq
fun main () =
src <- source 0;
me <- self;
ch <- channel;
dml (INSERT INTO peers (A, B, C)
VALUES ({[me]}, {[ch]}, {["Hi"]}));
rows <- queryX (SELECT * FROM peers WHERE peers.A > {[me]} OR peers.A < {[me]})
(fn row => <xml><tr>
<td>{[row.Peers.C]}</td>
<td>
<button value="Update" onclick={fn _ => n <- rpc (increment row.Peers.C); set src n}/>
</td>
</tr></xml>);
return <xml>
<head>
<title>Hello WebRTC!</title>
</head>
<body>
<h1>Hello WebRTC!</h1>
<table border=1>
<tr> <th>Client Name</th> <th>Connect</th> <th>Message</th> </tr>
{rows}
</table>
</body>
</xml>
database dbname=test
sql peers.sql
safeGet Peers/main
peers
val main : unit -> transaction page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment