Files
payload/packages/db-postgres/src/find.ts
2024-04-25 13:05:49 -04:00

41 lines
913 B
TypeScript

import type { Find } from 'payload/database'
import type { PayloadRequest, SanitizedCollectionConfig } from 'payload/types'
import toSnakeCase from 'to-snake-case'
import type { PostgresAdapter } from './types'
import { findMany } from './find/findMany'
export const find: Find = async function find(
this: PostgresAdapter,
{
collection,
limit,
locale,
page = 1,
pagination,
req = {} as PayloadRequest,
sort: sortArg,
where,
},
) {
const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config
const sort = typeof sortArg === 'string' ? sortArg : collectionConfig.defaultSort
const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug))
return findMany({
adapter: this,
fields: collectionConfig.fields,
limit,
locale,
page,
pagination,
req,
sort,
tableName,
where,
})
}