Kysely Query Architect

Creates type-safe Kysely database queries with explicit column selection and TypeScript inference.

1|Updated Aug 11, 2025
One-click install
npx skills add https://github.com/AdamAugustinsky/a3-stack-kysely --skill kysely-query-architect
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Kysely Query Architect
Source: https://github.com/AdamAugustinsky/a3-stack-kysely/tree/main/.claude/skills/kysely-query-architect
Command: npx skills add https://github.com/AdamAugustinsky/a3-stack-kysely --skill kysely-query-architect

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill guides writing type-safe Kysely queries following project patterns, ensuring explicit column selection, type inference, and centralized query reuse across classes.

Core Features & Use Cases

  • Explicit columns: prefer .select([...]) over selectAll().
  • Type inference: let Kysely infer return types; avoid manual typings.
  • Query reuse across classes: inject and compose query classes for shared dashboards and modules.
  • Performance patterns: use CTEs, joins, and parallelization with Promise.all.

Quick Start

Create a new query class in @packages/db/src/queries/*.ts, e.g., SalesQueries, with a constructor taking a Kysely<Database> and implementing methods like getSales(organizationId) that return .execute() results.

Frequently Asked Questions about Kysely Query Architect

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write type-safe database queries in TypeScript with Kysely?

Type-safe Kysely queries use explicit column selection with `.select([...])` and let Kysely infer return types automatically. Create query classes in `@packages/db/src/queries/*.ts` that inject a `Kysely<Database>` instance and return `.execute()` results, ensuring compile-time type safety without manual type annotations.

What's the best way to reuse database queries across multiple classes?

Compose query classes by injecting them as dependencies into other classes, allowing shared query logic for dashboards and modules. This pattern centralizes query builders and prevents duplication while maintaining type safety across your TypeScript project.

How do I optimize Kysely queries for performance?

Use Common Table Expressions (CTEs) and joins to structure complex queries efficiently, and parallelize independent queries with `Promise.all()`. Database-side logic for aggregations, filtering, and sorting reduces data transfer and improves execution speed.

Can I use Kysely with TypeScript without manual type definitions?

Yes. Kysely infers query result types from explicit column selections, eliminating manual type annotations. Define your database schema once as `Kysely<Database>`, and type inference handles the rest across all query methods.

When should I use explicit column selection instead of selectAll()?

Always prefer `.select([...])` to explicitly declare which columns you need. This improves query performance, reduces data transfer, makes dependencies explicit, and ensures type safety by preventing accidental exposure of sensitive or unused columns.

Why organize queries into separate classes under @packages/db/src/queries/?

Organizing queries into dedicated classes by domain (e.g., SalesQueries, UserQueries) centralizes related logic, enables dependency injection for reuse, supports team collaboration, and makes queries easier to test, maintain, and optimize across TypeScript projects.