# Query builder To create complex SQL queries, you need to use QueryBuilder > ⚠️ If you need basic CRUD operations and relationship support, use [Repository](Repository.md) Below is a code example of how to interact with QueryBuilder ```typescript const builder = new QueryBuilder() .setTable(SomeTable) // It`s @Table() class .setType(QueryType.INSERT) // Query type .setInsert( new InsertBuilder() .add('someStringColumn', 'value') .add('someNumberColumn', 1) ) ``` In this example we have created a builder that will insert a record into our table where `someStringColumn = 'value'` and `someNumberColumn = 1` To call this query, it is enough to call 2 methods ```typescript const builder : QueryBuilder = new QueryBuilder() // ... await builder.build().execute() ``` You can even do this without intermediate variables. ```typescript await new QueryBuilder() .setTable(SomeTable) .setType(QueryType.DELETE) .setWhere( new WhereBuilder() .equalAnd('userId', 1) ) .build() .execute() ``` ### What methods does QueryBuilder have? * **setType(type: QueryType)** - Sets the type of query (e.g., INSERT, DELETE, etc.). * **setInsert(insert: InsertBuilder)** - Specifies the INSERT values for the query. * **setTable(table: Module)** - Defines the table to be used in the query. * **setSelect(select: SelectBuilder)** - Specifies what to select from the table. * **setWhere(where: WhereBuilder)** - Adds a WHERE condition to the query. * **addOrder(column: string, type: 'ASC' | 'DESC')** - Adds the ORDER BY clause with descending order for a specific default. * **setLimit(limit: number)** - Limits the number of results returned by the query. * **setGroup(column: string)** - Specifies a GROUP BY clause for the query. * **setHaving(having: HavingBuilder)** - Adds a HAVING condition to the query. * **setOffset(offset: number)** - Specifies an OFFSET value for the query. * **setUpdate(update: UpdateBuilder)** - Specifies the UPDATE values for the query. * **setUseCache(use: boolean = true)** - Enable or disable caching this query * **setCacheTTL(ttl: number)** - Sets cache time to live * **setJoin(join: JoinBuilder)** - Specifies a JOIN ### [Next >](All%20builders.md)