@@ -6,9 +6,17 @@ import { createConditionExpression, type FilterOptions } from "./expression";
66import { maybeMerge } from "./object" ;
77import type { DynamoDBTypes , PK , SK } from "./types" ;
88
9- type CreateQueryOptions < Attributes extends DynamoDBTypes > = {
9+ type CreateQueryItemsOptions < Attributes extends DynamoDBTypes > = {
10+ tablename : string ;
1011 indexName ?: string ;
11- sortKeyName ?: keyof Attributes ;
12+ /**
13+ * Name of the Partitionkey Attribute
14+ */
15+ pkName : keyof Attributes ;
16+ /**
17+ * Name of the Sortkey Attribute
18+ */
19+ skName ?: keyof Attributes ;
1220} ;
1321
1422type QueryDynamoDBOptions = Omit < QueryCommandInput , "TableName" > ;
@@ -30,36 +38,33 @@ export type QueryItemsFunction<
3038
3139/**
3240 * Creates A function to query the Table
33- * @param tablename Name of DynamoDB Table
34- * @param options Key and GSI options
41+ * @param options Options for the query items function
3542 * @returns Function to query table
3643 */
3744export const createQueryItems = <
3845 Attributes extends DynamoDBTypes ,
3946 TPK extends PK ,
4047 TSK extends SK = undefined ,
4148> (
42- tablename : string ,
43- partitionKeyName : keyof Attributes ,
44- options : CreateQueryOptions < Attributes > ,
49+ options : CreateQueryItemsOptions < Attributes > ,
4550) : QueryItemsFunction < Attributes , TPK , TSK > => {
46- const { indexName, sortKeyName } = options ;
51+ const { indexName, skName , pkName , tablename } = options ;
4752
48- return ( key , options = { } ) => {
53+ return ( key , { sortKey , dynamodbOptions = { } , filterOptions } = { } ) => {
4954 const keyOptions = {
50- [ partitionKeyName ] : key ,
55+ [ pkName ] : key ,
5156
52- ...maybeMerge ( sortKeyName , options . sortKey ) ,
57+ ...maybeMerge ( skName , sortKey ) ,
5358 } as Partial < Attributes > ;
5459
5560 const queryOptions = createQueryOptions (
5661 keyOptions ,
5762 indexName ,
58- options . filterOptions ,
63+ filterOptions ,
5964 ) ;
6065
6166 return queryItems ( tablename , {
62- ...options . dynamodbOptions ,
67+ ...dynamodbOptions ,
6368 ...queryOptions ,
6469 } ) ;
6570 } ;
0 commit comments