# query

### Spec

```typescript
async query(
    tnmInput: TynamoQueryInput<TSource>
): Promise<TynamoQueryOutput<TSource>>
```

### Input&#x20;

```typescript
export interface TynamoQueryInput<TSource> {
    ExclusiveStartKey?: TSource;
    ExpressionAttributeValues?: any;

    // Derived from DynamoDB.
    IndexName?: IndexName;
    Select?: Select;
    Limit?: PositiveIntegerObject;
    ConsistentRead?: ConsistentRead;
    ScanIndexForward?: BooleanObject;
    ReturnConsumedCapacity?: ReturnConsumedCapacity;
    ProjectionExpression?: ProjectionExpression;
    FilterExpression?: ConditionExpression;
    KeyConditionExpression?: KeyExpression;
    ExpressionAttributeNames?: ExpressionAttributeNameMap;
}
```

| Name                      | Type            | Info                                                                                                                                                   |
| ------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ExclusiveStartKey         | `@DynamoEntity` | The primary key of the first item that this operation will evaluate. Use the value that was returned for `LastEvaluatedKey` in the previous operation. |
| ExpressionAttributeValues | `@DynamoEntity` | Value used for expression.                                                                                                                             |

{% hint style="info" %}
Unlisted param is derived from `DynamoDB`.

Check [here](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html) for more information.
{% endhint %}

### Output

```typescript
export interface TynamoQueryOutput<TSource> {
    Items?: TSource[];
    LastEvaluatedKey?: TSource;

    // Derived from DynamoDB.
    $response: AWS.Response<QueryOutput, AWS.AWSError>;
    Count?: Integer;
    ScannedCount?: Integer;
    ConsumedCapacity?: ConsumedCapacity;
}
```

| Name             | Type              | Info                          |
| ---------------- | ----------------- | ----------------------------- |
| Items            | `@DynamoEntity[]` | Result of `query` operation.  |
| LastEvaluatedKey | `@DynamoEntity`   | Primary key of the last item. |

{% hint style="info" %}
Unlisted param is derived from `DynamoDB`.

Check [here](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html) for more information.
{% endhint %}

### Example

```typescript
@DynamoEntity()
class Cat {
    @DynamoProperty({ keyType: KeyType.hash })
    id!: number;

    @DynamoProperty({ keyType: KeyType.attr })
    name!: string;

    constructor(id: number, name: string) {
        this.id = id;
        this.name = name;
    }
}

@DynamoEntity()
class Args {
    @DynamoProperty({ keyType: KeyType.hash })
    prefix!: string;
    
    constructor(prefix: string){
        this.prefix= prefix;
    }
}

const tynamo: Tynamo = new Tynamo({
    region: "ap-northeast-2",
    endpoint: "http://localhost:8000"
});
const tynamoTable = tynamo.getTableOf(Cat);


await tynamoTable.query({
    FilterExpression: "begins_with(#name, :prefix)",
    ExpressionAttributeValues: new Args("gar"),
    ProjectionExpression: "#id, #name"
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aerocode.gitbook.io/tynamo/tynamo-1/create-tynamo/tynamotable/query.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
