Created
January 18, 2018 16:15
-
-
Save jchris/fc329718369b7e8c9d01a3c39aa13626 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import faunadb, {query as q} from 'faunadb'; | |
const client = new faunadb.Client({ | |
secret: "XXXXXX" | |
}); | |
async function runThese() { | |
const ref = q.Ref(q.Class("posts"), 6) | |
await client.query(q.Create(ref, { data: { title: "Init" } })) | |
await client.query(q.Update(ref, { data: { title: "Edit 1" } })) | |
await client.query(q.Update(ref, { data: { title: "Edit 2" } })) | |
await client.query(q.Update(ref, { data: { title: "Edit 3" } })) | |
var res = await client.query(q.Map( | |
q.Paginate(ref, {events: true, size: 2}), | |
function(event) { | |
return q.Get(q.Select('resource', event), q.Select('ts', event)) | |
} | |
)) | |
console.log(res) | |
// [ | |
// { | |
// ref: Ref("classes/posts/9448519901"), | |
// class: Ref("classes/posts"), | |
// ts: 1516000908321276, | |
// data: { title: "Edit 4" } | |
// }, | |
// { | |
// ref: Ref("classes/posts/9448519901"), | |
// class: Ref("classes/posts"), | |
// ts: 1516000908673810, | |
// data: { title: "Edit 5" } | |
// } | |
// ] | |
var res = await client.query(q.Map( | |
q.Paginate(ref, {events: true, size: 2, after: res.after.ts}), | |
function(event) { | |
return q.Get(q.Select('resource', event), q.Select('ts', event)) | |
} | |
)).catch((e)=> console.log(e)) | |
console.log(res.data) | |
// [ { ref: Ref("classes/posts/6"), | |
// class: Ref("classes/posts"), | |
// ts: 1516124918186000, | |
// data: { title: 'Edit 1' } }, | |
// { ref: Ref("classes/posts/6"), | |
// class: Ref("classes/posts"), | |
// ts: 1516124918455250, | |
// data: { title: 'Edit 2' } } ] | |
var res = await client.query(q.Map( | |
q.Paginate(ref, {events: true, size: 2, after: 0}), | |
function(event) { | |
return q.Get(q.Select('resource', event), q.Select('ts', event)) | |
} | |
)) | |
console.log(res.data) | |
// [ | |
// { | |
// ref: Ref("classes/posts/9448519901"), | |
// class: Ref("classes/posts"), | |
// ts: 1516000908321276, | |
// data: { title: "Edit 4" } | |
// }, | |
// { | |
// ref: Ref("classes/posts/9448519901"), | |
// class: Ref("classes/posts"), | |
// ts: 1516000908673810, | |
// data: { title: "Edit 5" } | |
// } | |
// ] | |
} | |
runThese(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment