knex-query-building
Use when generating SQL with knex_dart query builders: filtering, joins, grouping, CTEs, unions, and SQL inspection.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Use when generating SQL with knex_dart query builders: filtering, joins, grouping, CTEs, unions, and SQL inspection.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Use when configuring connection pools, executing raw SQL, or tapping observability streams on knex_dart driver clients.
Use when choosing between SQL-only knex_dart usage and a live driver package, or when writing the first connected query.
Use when writing INSERT, UPDATE, DELETE, or conflict-handling queries with knex_dart.
Use when instrumenting knex_dart live driver wrappers with OpenTelemetry spans, DB client duration metrics, hooks, transactions, or stream/query interceptor behavior.
Use when defining database migrations with knex_dart's Migrator — code-first, SQL-directory, or schema-input styles.
Use when creating tables, altering schema, or running atomic write flows with knex_dart driver wrappers.
| name | knex-query-building |
| description | Use when generating SQL with knex_dart query builders: filtering, joins, grouping, CTEs, unions, and SQL inspection. |
Prefer KnexQuery for portable, compile-only examples. It gives you dialect-correct SQL without requiring a live database connection.
import 'package:knex_dart/knex_dart.dart';
final q = KnexQuery.forDialect(KnexDialect.postgres);
final sql = q
.from('users')
.select(['id', 'email'])
.where('active', '=', true)
.orderBy('name')
.limit(10)
.toSQL();
print(sql.sql);
print(sql.bindings); // [true]
Use KnexQuery.forClient('mysql2') or a different KnexDialect when you need another placeholder and quoting style.
final filtered = q
.from('users')
.where('status', '=', 'active')
.whereIn('role', ['admin', 'moderator'])
.whereNull('deleted_at')
.toSQL();
final grouped = q
.from('users')
.where((inner) => inner.where('a', '=', 1).orWhere('b', '=', 2))
.toSQL();
final compared = q
.from('posts')
.whereColumn('updated_at', '>', 'created_at')
.toSQL();
Useful helpers:
where(...), orWhere(...), whereNot(...)whereIn(...), whereNotIn(...)whereNull(...), whereNotNull(...)whereBetween(...), whereNotBetween(...)whereColumn(...), orWhereColumn(...)final joined = q
.from('users')
.leftJoin('orders', 'users.id', 'orders.user_id')
.select(['users.id', 'orders.id'])
.toSQL();
final callbackJoin = q
.from('users')
.join('orders', (j) {
j.on('users.id', '=', 'orders.user_id')
.andOnVal('orders.status', '=', 'completed');
})
.toSQL();
Prefer the callback form when you need andOnVal, orOn, onIn, or other complex ON conditions.
final grouped = q
.from('orders')
.select(['status'])
.count('id')
.groupBy('status')
.havingRaw('count(*) > ?', [5])
.toSQL();
For aliases inside aggregates, prefer raw fragments in the select list:
final totals = q
.from('orders')
.select([q.queryBuilder().client.raw('count(*) as total')])
.toSQL();
Use withQuery() because with is a Dart reserved word.
final cte = q.queryBuilder()
.withQuery(
'active_users',
q.from('users').select(['id', 'name']).where('active', '=', true),
)
.from('active_users')
.select(['id', 'name'])
.toSQL();
final unioned = q
.from('employees')
.select(['name'])
.union([
q.from('contractors').select(['name']),
])
.toSQL();
union(...), unionAll(...), intersect(...), and except(...) all take a list of queries.
This skill is about query-building patterns. End examples with .toSQL() unless you are using a driver-specific execution API in a separate context.
https://docs.knex.mahawarkartikey.in/raw/query-building/where-clauses.mdhttps://docs.knex.mahawarkartikey.in/raw/query-building/joins.mdhttps://docs.knex.mahawarkartikey.in/raw/query-building/subqueries.mdhttps://docs.knex.mahawarkartikey.in/raw/query-building/ctes.mdhttps://docs.knex.mahawarkartikey.in/raw/query-building/unions.md