Skip to content

Model

51 exports Added in v1.0.0 Source

Date & Time

Date

Added in v1.0.0 Source

A schema for a DateTime.Utc that is serialized as a date string in the format YYYY-MM-DD.

Signature

declare const Date: Date;

Date interface

Added in v1.0.0 Source

Signature

interface Date extends transformOrFail<String, any> {}

Signature

declare const DateTimeFromDate: DateTimeFromDate;

DateTimeFromDate interface

Added in v1.0.0 Source

Signature

interface DateTimeFromDate extends transform<any, any> {}

Signature

declare const DateTimeFromDateWithNow: any;

Signature

declare const DateTimeFromNumberWithNow: any;

A field that represents a date-time value that is inserted as the current DateTime.Utc. It is serialized as a string for the database.

It is omitted from updates and is available for selection.

Signature

declare const DateTimeInsert: DateTimeInsert;

DateTimeInsert interface

Added in v1.0.0 Source

Signature

interface DateTimeInsert extends unknown<{
  readonly insert: VariantSchema.Overrideable<DateTime.Utc, string>;
  readonly json: typeof Schema.DateTimeUtc;
  readonly select: typeof Schema.DateTimeUtc;
}> {}

A field that represents a date-time value that is inserted as the current DateTime.Utc. It is serialized as a Date for the database.

It is omitted from updates and is available for selection.

Signature

declare const DateTimeInsertFromDate: DateTimeInsertFromDate;

DateTimeInsertFromDate interface

Added in v1.0.0 Source

Signature

interface DateTimeInsertFromDate extends unknown<{
  readonly insert: VariantSchema.Overrideable<DateTime.Utc, globalThis.Date>;
  readonly json: typeof Schema.DateTimeUtc;
  readonly select: DateTimeFromDate;
}> {}

A field that represents a date-time value that is inserted as the current DateTime.Utc. It is serialized as a number.

It is omitted from updates and is available for selection.

Signature

declare const DateTimeInsertFromNumber: DateTimeInsertFromNumber;

DateTimeInsertFromNumber interface

Added in v1.0.0 Source

Signature

interface DateTimeInsertFromNumber extends unknown<{
  readonly insert: VariantSchema.Overrideable<DateTime.Utc, number>;
  readonly json: typeof Schema.DateTimeUtcFromNumber;
  readonly select: typeof Schema.DateTimeUtcFromNumber;
}> {}

A field that represents a date-time value that is updated as the current DateTime.Utc. It is serialized as a string for the database.

It is set to the current DateTime.Utc on updates and inserts and is available for selection.

Signature

declare const DateTimeUpdate: DateTimeUpdate;

DateTimeUpdate interface

Added in v1.0.0 Source

Signature

interface DateTimeUpdate extends unknown<{
  readonly insert: VariantSchema.Overrideable<DateTime.Utc, string>;
  readonly json: typeof Schema.DateTimeUtc;
  readonly select: typeof Schema.DateTimeUtc;
  readonly update: VariantSchema.Overrideable<DateTime.Utc, string>;
}> {}

A field that represents a date-time value that is updated as the current DateTime.Utc. It is serialized as a Date for the database.

It is set to the current DateTime.Utc on updates and inserts and is available for selection.

Signature

declare const DateTimeUpdateFromDate: DateTimeUpdateFromDate;

DateTimeUpdateFromDate interface

Added in v1.0.0 Source

Signature

interface DateTimeUpdateFromDate extends unknown<{
  readonly insert: VariantSchema.Overrideable<DateTime.Utc, globalThis.Date>;
  readonly json: typeof Schema.DateTimeUtc;
  readonly select: DateTimeFromDate;
  readonly update: VariantSchema.Overrideable<DateTime.Utc, globalThis.Date>;
}> {}

A field that represents a date-time value that is updated as the current DateTime.Utc. It is serialized as a number.

It is set to the current DateTime.Utc on updates and inserts and is available for selection.

Signature

declare const DateTimeUpdateFromNumber: DateTimeUpdateFromNumber;

DateTimeUpdateFromNumber interface

Added in v1.0.0 Source

Signature

interface DateTimeUpdateFromNumber extends unknown<{
  readonly insert: VariantSchema.Overrideable<DateTime.Utc, number>;
  readonly json: typeof Schema.DateTimeUtcFromNumber;
  readonly select: typeof Schema.DateTimeUtcFromNumber;
  readonly update: VariantSchema.Overrideable<DateTime.Utc, number>;
}> {}

Signature

declare const DateTimeWithNow: any;

DateWithNow

Added in v1.0.0 Source

Signature

declare const DateWithNow: any;

Fields

fields

Added in v1.0.0 Source

Signature

declare const fields: <A extends VariantSchema.Struct<any>>(self: A) => A[VariantSchema.TypeId];

Generated

Generated

Added in v1.0.0 Source

A field that represents a column that is generated by the database.

It is available for selection and update, but not for insertion.

Signature

declare const Generated: <S extends any>(schema: S) => Generated<S>;

Generated interface

Added in v1.0.0 Source

Signature

interface Generated<S extends Schema.Schema.All | Schema.PropertySignature.All> extends unknown<{
  readonly json: S;
  readonly select: S;
  readonly update: S;
}> {}

A field that represents a column that is generated by the application.

It is required by the database, but not by the JSON variants.

Signature

declare const GeneratedByApp: <S extends any>(schema: S) => GeneratedByApp<S>;

GeneratedByApp interface

Added in v1.0.0 Source

Signature

interface GeneratedByApp<
  S extends Schema.Schema.All | Schema.PropertySignature.All,
> extends unknown<{
  readonly insert: S;
  readonly json: S;
  readonly select: S;
  readonly update: S;
}> {}

Json

A field that represents a JSON value stored as text in the database.

The "json" variants will use the object schema directly.

Signature

declare const JsonFromString: <S extends any>(schema: S) => JsonFromString<S>;

JsonFromString interface

Added in v1.0.0 Source

Signature

interface JsonFromString<
  S extends Schema.Schema.All | Schema.PropertySignature.All,
> extends unknown<{
  readonly insert: Schema.Schema<Schema.Schema.Type<S>, string, Schema.Schema.Context<S>>;
  readonly json: S;
  readonly jsonCreate: S;
  readonly jsonUpdate: S;
  readonly select: Schema.Schema<Schema.Schema.Type<S>, string, Schema.Schema.Context<S>>;
  readonly update: Schema.Schema<Schema.Schema.Type<S>, string, Schema.Schema.Context<S>>;
}> {}

Models

Any type

Added in v1.0.0 Source

Signature

type Any = Schema.Schema.Any & {
  readonly fields: Schema.Struct.Fields;
  readonly insert: Schema.Schema.Any;
  readonly json: Schema.Schema.Any;
  readonly jsonCreate: Schema.Schema.Any;
  readonly jsonUpdate: Schema.Schema.Any;
  readonly update: Schema.Schema.Any;
};

AnyNoContext type

Added in v1.0.0 Source

Signature

type AnyNoContext = Schema.Schema.AnyNoContext & {
  readonly fields: Schema.Struct.Fields;
  readonly insert: Schema.Schema.AnyNoContext;
  readonly json: Schema.Schema.AnyNoContext;
  readonly jsonCreate: Schema.Schema.AnyNoContext;
  readonly jsonUpdate: Schema.Schema.AnyNoContext;
  readonly update: Schema.Schema.AnyNoContext;
};

VariantsDatabase type

Added in v1.0.0 Source

Signature

type VariantsDatabase = "select" | "insert" | "update";

VariantsJson type

Added in v1.0.0 Source

Signature

type VariantsJson = "json" | "jsonCreate" | "jsonUpdate";

Optional

FieldOption

Added in v1.0.0 Source

Convert a field to one that is optional for all variants.

For the database variants, it will accept nullable values. For the JSON variants, it will also accept missing keys.

Signature

declare const FieldOption: <Field extends any>(
  self: Field,
) => Field extends Any
  ? FieldOption<Field>
  : Field extends Field<S>
    ? Field<{
        [K in string | number | symbol]: S[K] extends Any
          ? K extends VariantsDatabase
            ? OptionFromNullOr<S[K]>
            : optionalWith<
                S[K],
                {
                  as: "Option";
                  nullable: true;
                }
              >
          : never;
      }>
    : never;

FieldOption interface

Added in v1.0.0 Source

Convert a field to one that is optional for all variants.

For the database variants, it will accept nullable values. For the JSON variants, it will also accept missing keys.

Signature

interface FieldOption<S extends Schema.Schema.Any> extends unknown<{
  readonly insert: Schema.OptionFromNullOr<S>;
  readonly json: Schema.optionalWith<
    S,
    {
      as: "Option";
    }
  >;
  readonly jsonCreate: Schema.optionalWith<
    S,
    {
      as: "Option";
      nullable: true;
    }
  >;
  readonly jsonUpdate: Schema.optionalWith<
    S,
    {
      as: "Option";
      nullable: true;
    }
  >;
  readonly select: Schema.OptionFromNullOr<S>;
  readonly update: Schema.OptionFromNullOr<S>;
}> {}

Other

Signature

declare const Class: any;

Signature

declare const extract: any;

Signature

declare const Field: any;

Signature

declare const fieldEvolve: any;

Signature

declare const FieldExcept: any;

Signature

declare const fieldFromKey: any;

Signature

declare const FieldOnly: any;

Signature

declare const Struct: any;

Signature

declare const Union: any;

Overrideable

Override

Added in v1.0.0 Source

Signature

declare const Override: <A>(value: A) => A & Brand<"Override">;

Repository

Create some simple data loaders from a model.

Signature

declare function makeDataLoaders<S extends any, Id extends string | number | symbol>(
  Model: S,
  options: {
    readonly idColumn: Id;
    readonly maxBatchSize?: number;
    readonly spanPrefix: string;
    readonly tableName: string;
    readonly window: DurationInput;
  },
): Effect<
  {
    readonly delete: (id: Type<S["fields"][Id]>) => Effect<void>;
    readonly findById: (id: Type<S["fields"][Id]>) => Effect<Option<S["Type"]>>;
    readonly insert: (insert: S["insert"]["Type"]) => Effect<S["Type"]>;
    readonly insertVoid: (insert: S["insert"]["Type"]) => Effect<void>;
  },
  never,
  SqlClient | Scope
>;

Create a simple CRUD repository from a model.

Signature

declare function makeRepository<S extends any, Id extends string | number | symbol>(
  Model: S,
  options: {
    readonly idColumn: Id;
    readonly spanPrefix: string;
    readonly tableName: string;
  },
): Effect<
  {
    readonly delete: (id: Type<S["fields"][Id]>) => Effect<void, never, Context<S["fields"][Id]>>;
    readonly findById: (id: Type<S["fields"][Id]>) => Effect<Option<S["Type"]>, never, any>;
    readonly insert: (
      insert: S["insert"]["Type"],
    ) => Effect<S["Type"], never, S["Context"] | S["insert"]["Context"]>;
    readonly insertVoid: (
      insert: S["insert"]["Type"],
    ) => Effect<void, never, S["Context"] | S["insert"]["Context"]>;
    readonly update: (
      update: S["update"]["Type"],
    ) => Effect<S["Type"], never, S["Context"] | S["update"]["Context"]>;
    readonly updateVoid: (
      update: S["update"]["Type"],
    ) => Effect<void, never, S["Context"] | S["update"]["Context"]>;
  },
  never,
  SqlClient
>;

Sensitive

Sensitive

Added in v1.0.0 Source

A field that represents a sensitive value that should not be exposed in the JSON variants.

Signature

declare const Sensitive: <S extends any>(schema: S) => Sensitive<S>;

Sensitive interface

Added in v1.0.0 Source

Signature

interface Sensitive<S extends Schema.Schema.All | Schema.PropertySignature.All> extends unknown<{
  readonly insert: S;
  readonly select: S;
  readonly update: S;
}> {}

Uuid

A boolean parsed from 0 or 1

Signature

declare class BooleanFromNumber extends any {
  constructor();
}

UuidV4Insert

Added in v1.0.0 Source

A field that represents a binary UUID v4 that is generated on inserts.

Signature

declare const UuidV4Insert: <B extends string | symbol>(schema: brand<any, B>) => UuidV4Insert<B>;

UuidV4Insert interface

Added in v1.0.0 Source

Signature

interface UuidV4Insert<B extends string | symbol> extends unknown<{
  readonly insert: VariantSchema.Overrideable<Uint8Array & Brand<B>, Uint8Array>;
  readonly json: Schema.brand<typeof Schema.Uint8ArrayFromSelf, B>;
  readonly select: Schema.brand<typeof Schema.Uint8ArrayFromSelf, B>;
  readonly update: Schema.brand<typeof Schema.Uint8ArrayFromSelf, B>;
}> {}

Signature

declare function UuidV4WithGenerate<B extends string | symbol>(
  schema: brand<any, B>,
): Overrideable<Uint8Array<ArrayBufferLike> & Brand<B>, Uint8Array<ArrayBufferLike>>;