1.0.0-beta.1 • Published 8 years ago
cozy-stack-link v1.0.0-beta.1
cozy-stack-link
The constructor
const link = new CozyStackLink(options)Options
uri: The Cozy instance URI ;token: The token given by the stack.
Collections
A collection is the set of all documents of a same doctype.
Selecting a collection is done by calling the collection() method, passing it the doctype:
const todos = link.collection('io.cozy.todos')Listing all documents
const allTodos = await todos.all()
console.log(allTodos.data)Pagination
By default, the link limits query results to 50 documents. If the limit causes some documents not to be returned, the response will have a next: true property.
By using the skip and limit options you can build your own pagination:
const firstPage = await todos.all({ limit: 100 })
if (firstPage.next) {
const secondPage = await todos.all({ skip: 100, limit: 100 })
}You can also use the meta.count property to know the total count of documents.
const allTodos = await todos.all()
console.log(`There are ${allTodos.meta.count} todos.`)Finding documents
const doneTodos = await todos.find({ done: true })
console.log(allTodos.data)1.0.0-beta.1
8 years ago