Skip to content

Instantly share code, notes, and snippets.

@benhinchley
Created October 17, 2018 06:05
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 benhinchley/902359e08f5eb5ea742cf02b9ecc72dd to your computer and use it in GitHub Desktop.
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
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