Skip to content

Instantly share code, notes, and snippets.

@n1k0

n1k0/batch.js

Last active Sep 1, 2016
Embed
What would you like to do?
Quick kinto-http batch sample data creation script
var opts = {headers: {Authorization: "Basic " + require("btoa")("test:test")}};
var c = new (require("kinto-http"))("http://0.0.0.0:8888/v1", opts);
var schema = {"type": "object", "properties": {"n": {"type": "number"}}};
var displayFields = ["n"];
c.createBucket("buck")
.then(() => c.bucket("buck").createCollection("coll", {
data: {schema, displayFields}
}))
.then(() => {
var r = new Array(100).fill().map((_, n) => ({n}));
c.bucket("buck").collection("coll").batch(b => {
for (var o of r){
b.createRecord(o);
}
});
})
.then(() => console.log("Done."));
@Natim

This comment has been minimized.

Copy link

@Natim Natim commented Sep 1, 2016

require("kinto-http")require("kinto-http").default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment