Last active
September 1, 2016 13:21
-
-
Save n1k0/684c2b7e3150b101376b2bd429b7b19f to your computer and use it in GitHub Desktop.
Quick kinto-http batch sample data creation script
This file contains 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
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.")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
require("kinto-http")
→require("kinto-http").default