Skip to content

Instantly share code, notes, and snippets.

@n1k0
Last active September 1, 2016 13:21
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 n1k0/684c2b7e3150b101376b2bd429b7b19f to your computer and use it in GitHub Desktop.
Save n1k0/684c2b7e3150b101376b2bd429b7b19f to your computer and use it in GitHub Desktop.
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
Copy link

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