Type alias ToDBType<T, DateString, ObjectType>
ToDBType<T, DateString, ObjectType>: {
[P in keyof T]-?: NonNullable<T[P]> extends Date
? T[P] extends NonNullable<T[P]>
? DateString extends false
? Date
: string
: (DateString extends false
? Date
: string) | null
: NonNullable<T[P]> extends object | unknown[]
? T[P] extends NonNullable<T[P]>
? ObjectType
: ObjectType | null
: T[P] extends NonNullable<T[P]>
? T[P]
: NonNullable<T[P]> | null
}
Type Parameters
-
T extends object
-
DateString extends boolean = false
-
ObjectType = string
Change a type into what would be returned from the database
e.g. any object or array will be returned as a JSON string, except Date which is returned from the Database by default.
To convert dates to strings as well, pass
true
into the second template parameterTo convert objects/arrays into something other than strings, use the third template parameter to set what they will be returned as