Compare commits

...

1 Commits

Author SHA1 Message Date
Germán Jabloñski
b65588f79d Revert "fix(db-postgres): sort by distance when the near operator is used (…"
This reverts commit 9955818503.
2025-04-24 16:19:31 -03:00
4 changed files with 14 additions and 26 deletions

View File

@@ -3,14 +3,12 @@ import type { FlattenedField, Where } from 'payload'
import type { DrizzleAdapter, GenericColumn } from '../types.js'
import type { BuildQueryJoinAliases } from './buildQuery.js'
import type { QueryContext } from './parseParams.js'
import { parseParams } from './parseParams.js'
export function buildAndOrConditions({
adapter,
aliasTable,
context,
fields,
joins,
locale,
@@ -23,7 +21,6 @@ export function buildAndOrConditions({
adapter: DrizzleAdapter
aliasTable?: Table
collectionSlug?: string
context: QueryContext
fields: FlattenedField[]
globalSlug?: string
joins: BuildQueryJoinAliases
@@ -44,7 +41,6 @@ export function buildAndOrConditions({
const result = parseParams({
adapter,
aliasTable,
context,
fields,
joins,
locale,

View File

@@ -3,7 +3,6 @@ import type { PgTableWithColumns } from 'drizzle-orm/pg-core'
import type { FlattenedField, Sort, Where } from 'payload'
import type { DrizzleAdapter, GenericColumn, GenericTable } from '../types.js'
import type { QueryContext } from './parseParams.js'
import { buildOrderBy } from './buildOrderBy.js'
import { parseParams } from './parseParams.js'
@@ -53,14 +52,24 @@ const buildQuery = function buildQuery({
id: adapter.tables[tableName].id,
}
const orderBy = buildOrderBy({
adapter,
aliasTable,
fields,
joins,
locale,
parentIsLocalized,
selectFields,
sort,
tableName,
})
let where: SQL
const context: QueryContext = { sort }
if (incomingWhere && Object.keys(incomingWhere).length > 0) {
where = parseParams({
adapter,
aliasTable,
context,
fields,
joins,
locale,
@@ -72,18 +81,6 @@ const buildQuery = function buildQuery({
})
}
const orderBy = buildOrderBy({
adapter,
aliasTable,
fields,
joins,
locale,
parentIsLocalized,
selectFields,
sort: context.sort,
tableName,
})
return {
joins,
orderBy,

View File

@@ -1,5 +1,5 @@
import type { SQL, Table } from 'drizzle-orm'
import type { FlattenedField, Operator, Sort, Where } from 'payload'
import type { FlattenedField, Operator, Where } from 'payload'
import { and, isNotNull, isNull, ne, notInArray, or, sql } from 'drizzle-orm'
import { PgUUID } from 'drizzle-orm/pg-core'
@@ -14,12 +14,9 @@ import { buildAndOrConditions } from './buildAndOrConditions.js'
import { getTableColumnFromPath } from './getTableColumnFromPath.js'
import { sanitizeQueryValue } from './sanitizeQueryValue.js'
export type QueryContext = { sort: Sort }
type Args = {
adapter: DrizzleAdapter
aliasTable?: Table
context: QueryContext
fields: FlattenedField[]
joins: BuildQueryJoinAliases
locale?: string
@@ -33,7 +30,6 @@ type Args = {
export function parseParams({
adapter,
aliasTable,
context,
fields,
joins,
locale,
@@ -61,7 +57,6 @@ export function parseParams({
const builtConditions = buildAndOrConditions({
adapter,
aliasTable,
context,
fields,
joins,
locale,
@@ -347,7 +342,6 @@ export function parseParams({
)
}
if (geoConstraints.length) {
context.sort = relationOrPath
constraints.push(and(...geoConstraints))
}
break

View File

@@ -1218,6 +1218,7 @@ describe('collections-rest', () => {
.GET(`/${pointSlug}`, {
query: {
limit: 5,
sort: 'point',
where: {
point: {
// querying large enough range to include all docs