Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/orm/src/client/client-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
type KyselyProps,
} from 'kysely';
import type { GetModels, ProcedureDef, SchemaDef } from '../schema';
import type { AnyKysely } from '../utils/kysely-utils';
import type { UnwrapTuplePromises } from '../utils/type-utils';
import type {
AuthType,
Expand Down Expand Up @@ -53,7 +54,7 @@ export const ZenStackClient = function <Schema extends SchemaDef>(

export class ClientImpl<Schema extends SchemaDef> {
private kysely: ToKysely<Schema>;
private kyselyRaw: ToKysely<any>;
private kyselyRaw: AnyKysely;
public readonly $options: ClientOptions<Schema>;
public readonly $schema: Schema;
readonly kyselyProps: KyselyProps;
Expand Down Expand Up @@ -192,7 +193,7 @@ export class ClientImpl<Schema extends SchemaDef> {
arg: ZenStackPromise<Schema, any>[],
options?: { isolationLevel?: TransactionIsolationLevel },
) {
const execute = async (tx: Kysely<any>) => {
const execute = async (tx: AnyKysely) => {
const txClient = new ClientImpl<Schema>(this.schema, this.$options, this);
txClient.kysely = tx;
const result: any[] = [];
Expand All @@ -210,7 +211,7 @@ export class ClientImpl<Schema extends SchemaDef> {
if (options?.isolationLevel) {
txBuilder = txBuilder.setIsolationLevel(options.isolationLevel);
}
return txBuilder.execute((tx) => execute(tx as Kysely<any>));
return txBuilder.execute((tx) => execute(tx as AnyKysely));
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/orm/src/client/contract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type Decimal from 'decimal.js';
import { type GetModels, type IsDelegateModel, type ProcedureDef, type SchemaDef } from '../schema';
import type { AnyKysely } from '../utils/kysely-utils';
import type { OrUndefinedIf, Simplify, UnwrapTuplePromises } from '../utils/type-utils';
import type { TRANSACTION_UNSUPPORTED_METHODS } from './constants';
import type {
Expand Down Expand Up @@ -116,7 +117,7 @@ export type ClientContract<Schema extends SchemaDef> = {
/**
* The raw Kysely query builder without any ZenStack enhancements.
*/
readonly $qbRaw: ToKysely<any>;
readonly $qbRaw: AnyKysely;

/**
* Starts an interactive transaction.
Expand Down
16 changes: 9 additions & 7 deletions packages/orm/src/client/crud/dialects/base-dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
}

buildFilterSortTake(
model: GetModels<Schema>,
model: string,
args: FindArgs<Schema, GetModels<Schema>, true>,
query: SelectQueryBuilder<any, any, {}>,
modelAlias: string,
Expand Down Expand Up @@ -767,7 +767,7 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
invariant(v === 'asc' || v === 'desc', `invalid orderBy value for field "${field}"`);
result = result.orderBy(
(eb) => aggregate(eb, buildFieldRef(model, k, modelAlias), field as AGGREGATE_OPERATORS),
sql.raw(this.negateSort(v, negated)),
this.negateSort(v, negated),
);
}
continue;
Expand All @@ -780,7 +780,7 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
invariant(v === 'asc' || v === 'desc', `invalid orderBy value for field "${field}"`);
result = result.orderBy(
(eb) => eb.fn.count(buildFieldRef(model, k, modelAlias)),
sql.raw(this.negateSort(v, negated)),
this.negateSort(v, negated),
);
}
continue;
Expand All @@ -803,10 +803,12 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
(value.sort === 'asc' || value.sort === 'desc') &&
(value.nulls === 'first' || value.nulls === 'last')
) {
result = result.orderBy(
fieldRef,
sql.raw(`${this.negateSort(value.sort, negated)} nulls ${value.nulls}`),
);
result = result.orderBy(fieldRef, (ob) => {
const dir = this.negateSort(value.sort, negated);
ob = dir === 'asc' ? ob.asc() : ob.desc();
ob = value.nulls === 'first' ? ob.nullsFirst() : ob.nullsLast();
return ob;
});
}
} else {
// order by relation
Expand Down
Loading