Skip to content

Commit e9e1d3a

Browse files
committed
Make it possible to add ScheduleAt in regular objects, not just rows.
1 parent 6a1539c commit e9e1d3a

2 files changed

Lines changed: 52 additions & 13 deletions

File tree

crates/bindings-typescript/src/lib/table.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,19 @@ export function table<Row extends RowObj, const Opts extends TableOpts<Row>>(
289289
});
290290
}
291291

292-
if (meta.isScheduleAt) {
293-
scheduleAtCol = colIds.get(name)!;
292+
// If this column is shaped like ScheduleAtAlgebraicType, mark it as the schedule‑at column
293+
if (scheduled) {
294+
const algebraicType = builder.typeBuilder.algebraicType;
295+
if (
296+
algebraicType.tag === 'Sum' &&
297+
algebraicType.value.variants.length === 2 &&
298+
algebraicType.value.variants[0].name === 'Interval' &&
299+
algebraicType.value.variants[1].name === 'Time'
300+
) {
301+
scheduleAtCol = colIds.get(name)!;
302+
}
294303
}
304+
295305
}
296306

297307
// convert explicit multi‑column indexes coming from options.indexes

crates/bindings-typescript/src/lib/type_builders.ts

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type BinaryWriter from './binary_writer';
44
import { ConnectionId, type ConnectionIdAlgebraicType } from './connection_id';
55
import { Identity, type IdentityAlgebraicType } from './identity';
66
import { Option, type OptionAlgebraicType } from './option';
7-
import ScheduleAt from './schedule_at';
7+
import ScheduleAt, { type ScheduleAtAlgebraicType } from './schedule_at';
88
import type { CoerceRow } from './table';
99
import { TimeDuration, type TimeDurationAlgebraicType } from './time_duration';
1010
import { Timestamp, type TimestampAlgebraicType } from './timestamp';
@@ -1487,6 +1487,26 @@ export const SimpleSumBuilder: {
14871487
export type SimpleSumBuilder<Variants extends SimpleVariantsObj> =
14881488
SimpleSumBuilderImpl<Variants> & SumBuilderVariantConstructors<Variants>;
14891489

1490+
export class ScheduleAtBuilder
1491+
extends TypeBuilder<ScheduleAt, ScheduleAtAlgebraicType>
1492+
implements
1493+
Defaultable<ScheduleAt, ScheduleAtAlgebraicType>
1494+
{
1495+
constructor() {
1496+
super(ScheduleAt.getAlgebraicType());
1497+
}
1498+
default(
1499+
value: ScheduleAt
1500+
): ScheduleAtColumnBuilder<
1501+
SetField<DefaultMetadata, 'defaultValue', ScheduleAt>
1502+
> {
1503+
return new ScheduleAtColumnBuilder(
1504+
this,
1505+
set(defaultMetadata, { defaultValue: value })
1506+
);
1507+
}
1508+
}
1509+
14901510
export class IdentityBuilder
14911511
extends TypeBuilder<Identity, IdentityAlgebraicType>
14921512
implements
@@ -1748,7 +1768,6 @@ export type ColumnMetadata<Type = any> = {
17481768
isPrimaryKey?: true;
17491769
isUnique?: true;
17501770
isAutoIncrement?: true;
1751-
isScheduleAt?: true;
17521771
indexType?: IndexTypes;
17531772
defaultValue?: Type;
17541773
};
@@ -2727,6 +2746,23 @@ export class SimpleSumColumnBuilder<
27272746
}
27282747
}
27292748

2749+
export class ScheduleAtColumnBuilder<
2750+
M extends ColumnMetadata<ScheduleAt> = DefaultMetadata,
2751+
>
2752+
extends ColumnBuilder<ScheduleAt, ScheduleAtAlgebraicType, M>
2753+
implements
2754+
Defaultable<ScheduleAt, ScheduleAtAlgebraicType>
2755+
{
2756+
default(
2757+
value: ScheduleAt
2758+
): ScheduleAtColumnBuilder<SetField<M, 'defaultValue', ScheduleAt>> {
2759+
return new ScheduleAtColumnBuilder(
2760+
this.typeBuilder,
2761+
set(this.columnMetadata, { defaultValue: value })
2762+
);
2763+
}
2764+
}
2765+
27302766
export class IdentityColumnBuilder<
27312767
M extends ColumnMetadata<Identity> = DefaultMetadata,
27322768
>
@@ -3241,15 +3277,8 @@ export const t = {
32413277
* This is a special helper function for conveniently creating {@link ScheduleAt} type columns.
32423278
* @returns A new ColumnBuilder instance with the {@link ScheduleAt} type.
32433279
*/
3244-
scheduleAt: (): ColumnBuilder<
3245-
ScheduleAt,
3246-
ReturnType<typeof ScheduleAt.getAlgebraicType>,
3247-
Omit<ColumnMetadata<ScheduleAt>, 'isScheduleAt'> & { isScheduleAt: true }
3248-
> => {
3249-
return new ColumnBuilder(
3250-
new TypeBuilder(ScheduleAt.getAlgebraicType()),
3251-
set(defaultMetadata, { isScheduleAt: true })
3252-
);
3280+
scheduleAt: (): ScheduleAtBuilder => {
3281+
return new ScheduleAtBuilder();
32533282
},
32543283

32553284
/**

0 commit comments

Comments
 (0)