Dataset
The Dataset
class is an internal class that represents a Glacier Dataset.
Properties
name
The name of current dataset.
Methods
collection
Returns a reference to a Glacier Collection under current dataset.
Type
class Dataset {
collection<T = any>(name: string): Collection<T>
}
Example
interface RecordItem {
title: string
content: string
createdAt?: number
updatedAt?: number
}
const myNamespace = client.namespace('myproject')
const myDataset = myNamespace.dataset('mydataset')
const myCollection = myDataset.collection<RecordItem>('myrecords')
createCollection
Create a new Collection with the specified name under current dataset.
Type
class Dataset {
createCollection(
name: string,
schema: JSONSchema7Definition
): Promise<InsertResult>
}
Details
Schema needs to be specified when creating a collection, https://json-schema.org/learn/getting-started-step-by-step
Example
async function createCollection() {
const result = await client
.namespace(NamespaceName)
.dataset(DatasetName)
.createCollection(CollectionName, {
title: 'Records',
type: 'object',
properties: {
title: {
type: 'string',
maxLength: 200
},
content: {
type: 'string',
maxLength: 5000
},
createdAt: {
type: 'number'
},
updatedAt: {
type: 'number'
}
},
required: ['title', 'content']
})
console.log(result)
}