functional-models
    Preparing search index...

    Interface DatabaseKeyPropertyConfig<TValue>

    A property that represents a key in a database. By default it is a "uuid" type, but if you want to use an arbitrary string, or an integer type you can set the dataType property.

    interface DatabaseKeyPropertyConfig<TValue extends PrimaryKeyType> {
        auto?: boolean;
        autoNow?: boolean;
        choices?: readonly ChoiceTypes[];
        dataType?: PrimaryKeyPropertyType;
        defaultValue?: TValue;
        description?: string;
        fetcher?: ModelInstanceFetcher<object, object>;
        isArray?: boolean;
        isBoolean?: boolean;
        isDenormalized?: boolean;
        isInteger?: boolean;
        isNumber?: boolean;
        isString?: boolean;
        lazyLoadMethod?: <TData extends Readonly<{ [s: string]: any }>>(
            value: TValue,
            modelData: CreateParams<TData>,
        ) => TValue;
        lazyLoadMethodAtomic?: <TData extends Readonly<{ [s: string]: any }>>(
            value: TValue,
            modelData: CreateParams<TData>,
        ) => Promise<TValue>;
        maxLength?: number;
        maxValue?: number;
        minLength?: number;
        minValue?: number;
        primaryKeyGenerator?: PrimaryKeyGenerator;
        required?: boolean;
        typeOverride?: string;
        validators?: readonly PropertyValidatorComponent<any, object, object>[];
        value?: TValue;
        valueSelector?: (instanceValue: MaybePromise<TValue>) => TValue;
        zod?: ZodType<any, unknown, $ZodTypeInternals<any, unknown>>;
    }

    Type Parameters

    Index

    Properties

    auto?: boolean

    If true, the key will be automatically generated if not provided. Only applies to uuids and integers

    true
    
    autoNow?: boolean

    If the value should be created automatically. Used in date creation.

    choices?: readonly ChoiceTypes[]

    Possible limiting choices of what the property can be.

    Sets the type of the key.

    PrimaryKeyDataType.Uuid
    
    defaultValue?: TValue

    A default value if one is never given.

    description?: string

    A short human readable description of the property for documentation.

    fetcher?: ModelInstanceFetcher<object, object>

    If you are using ModelReferences, this is required. A fetcher used for getting model references. This configuration item is used within the AdvancedModelReferenceProperty and any other property that is lazy loading (atomically) models.

    isArray?: boolean

    Is the property an array of values?

    isBoolean?: boolean

    Is the property only true or false?

    isDenormalized?: boolean

    Determines if this value needs to go through denormalization.

    isInteger?: boolean

    Can the property only be an integer?

    isNumber?: boolean

    Can the property only be a number?

    isString?: boolean

    Can the property only be a string?

    lazyLoadMethod?: <TData extends Readonly<{ [s: string]: any }>>(
        value: TValue,
        modelData: CreateParams<TData>,
    ) => TValue

    A lazy loading method, which will only run when the value is actually retrieved. IMPORTANT: Do not include promises as part of this because they are not thread safe.

    Type Declaration

      • <TData extends Readonly<{ [s: string]: any }>>(
            value: TValue,
            modelData: CreateParams<TData>,
        ): TValue
      • Type Parameters

        • TData extends Readonly<{ [s: string]: any }>

        Parameters

        Returns TValue

    lazyLoadMethodAtomic?: <TData extends Readonly<{ [s: string]: any }>>(
        value: TValue,
        modelData: CreateParams<TData>,
    ) => Promise<TValue>

    A thread safe (Atomic) version of lazyLoadMethod. Use this for all lazy loadings that requires Promises.

    Type Declaration

      • <TData extends Readonly<{ [s: string]: any }>>(
            value: TValue,
            modelData: CreateParams<TData>,
        ): Promise<TValue>
      • Type Parameters

        • TData extends Readonly<{ [s: string]: any }>

        Parameters

        Returns Promise<TValue>

    maxLength?: number

    The maximum length of the value. (Drives validation)

    maxValue?: number

    The maximum size of the value. (Drives validation)

    minLength?: number

    The minimum length of the value. (Drives validation)

    minValue?: number

    The minimum size of the value. (Drives validation)

    primaryKeyGenerator?: PrimaryKeyGenerator

    Optional: A custom primary key generator function to use for models. If the property type is UniqueId (default) then this will produce random UUID. If the property type is a number, a random number will be generated. If using a SQL-like database that uses numbers, its HIGHLY recommended to get a number from the database itself.

    required?: boolean

    Is this property required?

    typeOverride?: string

    A type override to override the property type of a property.

    validators?: readonly PropertyValidatorComponent<any, object, object>[]

    Additional validators for the property.

    value?: TValue

    The value of the property (if provided)

    valueSelector?: (instanceValue: MaybePromise<TValue>) => TValue

    An optional function that can select a "part" of the value to return.

    zod?: ZodType<any, unknown, $ZodTypeInternals<any, unknown>>

    An optional zod schema for this property. If provided, it will be used as an override for the generated schema.