Skip to main content

Any

Introduction

Any type provided by DynamoQL is an union type of all DynamoQL types.

TypeScript equivalent type is:

type DemoAnyType = string | number | bigint | null | boolean | Buffer | Set<string | number | bigint | Buffer> | Record<string, DemoAnyType> | DemoAnyType[]
import { Schema, Any } from "dynamoql";
import { randomUUID } from "crypto";

const userSchema = new Schema({
id: {
type: String,
primaryIndex: true,
default: randomUUID
},
someRequiredData: Any,
someOptionnalField: {
type: Any
}
} as const);
info

Any type's stored data type will depend on provided value.
An attribute with Any type accepts all DynamoQL types except Date.

Recommandation

Use Any type only when strictly necessary.
Always prefer union types like { myField: [String, Number, ...] } when possible.

Options

- required

boolean which makes attribute as required or optionnal, default is false when type is defined with an Object.

import { Schema, Any } from "dynamoql";
import { randomUUID } from "crypto";

const userSchema = new Schema({
id: {
type: String,
primaryIndex: true,
default: randomUUID
},
someData: {
type: Any,
required: true
}
} as const);

- default

To set a default value for an attribute use default option.

import { Schema, Any } from "dynamoql";
import { randomUUID } from "crypto";

const userSchema = new Schema({
id: {
type: String,
primaryIndex: true,
default: randomUUID
},
someData: {
type: Any,
default: null
}
} as const);

With this configuration when you put an Item into your table, your Item will contain someData attribute with null as value.

default can also be a (async) function which accepts one argument (put Item value).

import { Schema, Any } from "dynamoql";
import { randomUUID } from "crypto";

const userSchema = new Schema({
id: {
type: String,
primaryIndex: true,
default: randomUUID
},
moderator: Boolean,
someData: {
type: Any,
default: (item: Record<string, any>)=> {
if(item.moderator) {
return false
}
return false
}
}
} as const);

- description

add any information to the Schema for your personal usage.