Created
October 17, 2018 06:05
-
-
Save benhinchley/902359e08f5eb5ea742cf02b9ecc72dd to your computer and use it in GitHub Desktop.
an example of how to create a sajari schema with @sajari/sdk-node
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
const sajari = require("@sajari/sdk-node") | |
const SajariProject = "<your-project>"; | |
const SajariCollection = "<your-collection>"; | |
const SajariCredentials = { | |
key: "<your-api-key>", | |
secret: "<your-api-secret>" | |
}; | |
// create client | |
const client = new sajari.Client(SajariProject, SajariCollection, { | |
key: SajariCredentials.key, | |
secret: SajariCredentials.secret | |
}); | |
// get schema client from client | |
const schema = client.schema(); | |
/* | |
create schema fields | |
Schema fields can be one of the following types | |
- string | |
- integer | |
- float | |
- double | |
- boolean | |
- timestamp | |
Each field constructor takes and optional options object of the following shape | |
options: { | |
// Description is a description of the field. | |
description: string; | |
// Repeated indicates that this field can hold a list of values. | |
repeated: boolean; | |
// Required indicates that this field should always be set on all records. | |
required: boolean; | |
// Unique indicates that the field is unique (and this will | |
// be encoforced when new records are added). Unique fields can | |
// be used to retrieve/delete records. | |
unique: boolean; | |
} | |
*/ | |
const fields = [ | |
schema.string("field_name" /* options = {} */), | |
schema.integer("field_name" /* options = {} */), | |
schema.float("field_name" /* options = {} */), | |
schema.double("field_name" /* options = {} */), | |
schema.boolean("field_name" /* options = {} */), | |
schema.timestamp("field_name" /* options = {} */) | |
]; | |
schema.add(...fields).catch((err) => { | |
if (err) { | |
// handle error | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment