Skip to content

Commit 8e18efe

Browse files
committed
fix branded types and source
1 parent fe3f88f commit 8e18efe

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/render.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ const get_column_type = ({
156156
})();
157157

158158
if (branded) {
159-
return `SqlType<${final_type}, '${db_type}', '${source}'>`;
159+
const final_source = source !== '' ? `'${source}'` : 'never';
160+
return `SqlType<${final_type}, '${db_type}', ${final_source}>`;
160161
}
161162

162163
return final_type;
@@ -204,12 +205,17 @@ type ExecFn<TRow, TParam> = [TParam] extends [never]
204205
params: TParam & Record<string, unknown>,
205206
) => Promise<Array<ApplyOverride<TSpec, TRow>>>;
206207
207-
class BrandedSqlType<TDbType, TDbSource> {
208-
protected __dbtype: TDbType;
209-
protected __dbsource: TDbSource;
210-
}
211-
212-
type SqlType<T, TDbType, TDbSource> = T & BrandedSqlType<TDbType, TDbSource>;
208+
type SqlType<T, TDbType, TDbSource> = T & {
209+
/**
210+
* @deprecated this property does not exist in runtime, it is used for type-checking, do not use it in runtime!
211+
*/
212+
__dbtype: TDbType;
213+
214+
/**
215+
* @deprecated this property does not exist in runtime, it is used for type-checking, do not use it in runtime!
216+
*/
217+
__dbsource: TDbSource;
218+
};
213219
214220
class Query<TRow, TParam> {
215221
public query;

tests/src/sqlc.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ type ExecFn<TRow, TParam> = [TParam] extends [never]
3030
params: TParam & Record<string, unknown>,
3131
) => Promise<Array<ApplyOverride<TSpec, TRow>>>;
3232

33-
class BrandedSqlType<TDbType, TDbSource> {
34-
protected __dbtype: TDbType;
35-
protected __dbsource: TDbSource;
36-
}
33+
type SqlType<T, TDbType, TDbSource> = T & {
34+
/**
35+
* @deprecated this property does not exist in runtime, it is used for type-checking, do not use it in runtime!
36+
*/
37+
__dbtype: TDbType;
3738

38-
type SqlType<T, TDbType, TDbSource> = T & BrandedSqlType<TDbType, TDbSource>;
39+
/**
40+
* @deprecated this property does not exist in runtime, it is used for type-checking, do not use it in runtime!
41+
*/
42+
__dbsource: TDbSource;
43+
};
3944

4045
class Query<TRow, TParam> {
4146
public query;
@@ -187,7 +192,7 @@ const queries = {
187192
HAVING
188193
customer_id = @customer_id
189194
`]: new Query<
190-
{ customer_id: SqlType<number, 'int4', 'rental.customer_id'>; rental_count: SqlType<number, 'bigint', ''> },
195+
{ customer_id: SqlType<number, 'int4', 'rental.customer_id'>; rental_count: SqlType<number, 'bigint', never> },
191196
{ customer_id: number }
192197
>(
193198
`SELECT

0 commit comments

Comments
 (0)