git ssb

16+

Dominic / patchbay



Commit d2fc6470c2fee9649507c15c3061c53c9fcfa47d

/query : add an example query to get people started!

mix irving committed on 7/14/2018, 1:33:07 AM
Parent: 99e3e200407b1301e0075446b91def9b0ff643eb

Files changed

app/page/query.jschanged
app/page/query.mcsschanged
app/page/query.jsView
@@ -40,15 +40,15 @@
4040 if (!Array.isArray(query)) return
4141 if (!query.map(q => Object.keys(q)[0]).every(q => ['$filter', '$map', '$reduce'].includes(q))) return
4242 activateQuery()
4343 })
44- const query = Value([])
44 + const query = Value(json5.parse(initial()))
4545
4646 const activateQuery = () => query.set(json5.parse(input()))
4747
48- return h('Query', [
48 + return h('Query', { title: '/query' }, [
4949 h('section.query', [
50- h('textarea', { 'ev-input': ev => input.set(ev.target.value) }),
50 + h('textarea', { 'ev-input': ev => input.set(ev.target.value), value: initial() }),
5151 h('button', {
5252 className: when(error, '', '-primary'),
5353 disabled: when(error, 'disabled'),
5454 'ev-click': activateQuery
@@ -57,9 +57,13 @@
5757 h('section.output', [
5858 computed(query, query => {
5959 return Scroller({
6060 streamToBottom: source(query),
61- render: msg => h('pre', JSON.stringify(msg, null, 2))
61 + render: msg => h('pre', JSON.stringify(msg, null, 2)),
62 + comparer: (a, b) => {
63 + if (a && b && a.key && b.key) return a.key === b.key
64 + return a === b
65 + }
6266 })
6367 })
6468 ])
6569 ])
@@ -68,12 +72,33 @@
6872 function source (query) {
6973 const opts = {
7074 query,
7175 reverse: true,
72- limit: 100
76 + limit: 50
7377 }
7478
7579 return api.sbot.pull.stream(server => {
7680 return next(server.query.read, opts, ['value', 'timestamp'])
7781 })
7882 }
7983 }
84 +
85 +function initial () {
86 + return `[{
87 + $filter: {
88 + value: {
89 + timestamp: {$gt: 0},
90 + content: {
91 + type: 'post'
92 + }
93 + }
94 + }
95 +}, {
96 + $map: {
97 + receivedTimestamp: ['timestamp'],
98 + assertedTimestamp: ['value', 'timestamp'],
99 + author: ['value', 'author'],
100 + content: ['value', 'content']
101 + }
102 +}]
103 +`
104 +}
app/page/query.mcssView
@@ -22,9 +22,9 @@
2222 background: rgb(40 , 0, 40)
2323 padding: 1rem
2424 border: none
2525
26- min-height: 20rem
26 + min-height: 40rem
2727 }
2828
2929 button {
3030

Built with git-ssb-web