[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EQ95FEYVT2Q70F4A66RZSF":3,"skill-same:01M7EQ95FEYVT2Q70F4A66RZSF":47},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":25,"commitSha":26,"skillDirectory":27,"forksCount":28,"repositoryHtmlUrl":29,"repositoryHomepageUrl":6,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":6,"updatedAt":32,"install":33,"resources":46},"01M7EQ95FEYVT2Q70F4A66RZSF","knex-pro",null,"Knex.js query-builder guidance — migrations, seeds, transactions, query patterns, and production config.","TanNhatCMS\u002Fjarvis","TanNhatCMS","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F113796420?v=4","01M753MV17KG5CD3152G3WQEQY","KietNT","01M7EKEDYVYQ6PWVJJMZ911VMX",0,"MIT","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fams-knex-pro\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: knex-pro\ndescription: Knex.js query-builder guidance — migrations, seeds, transactions, query patterns, and production config.\ncategory: development\n---\n\n## Overview\n\nKnex is a SQL query builder for Node.js — not an ORM. It gives you composable, parameterized queries across Postgres, MySQL, SQLite, and MSSQL without hiding the SQL. Teams that want full control over their queries, or that find ORMs too magical, use Knex as the sane middle ground between raw SQL strings and a full object mapper.\n\nWith that control comes responsibility: there's no model layer to lean on, so schema knowledge lives in your migrations and your discipline. This skill covers Knex migrations, transaction patterns, query composition, and production configuration.\n\n## When to use\n\n- Building a Node.js data layer with explicit SQL control.\n- Writing and organizing Knex migrations and seeds.\n- Composing dynamic queries (filters, sorting, pagination).\n- Managing transactions correctly in Knex.\n- Choosing between Knex, an ORM, and raw SQL.\n- Using Knex with Objection.js as a model layer on top.\n- Tuning connection pools for production.\n\n## Core concepts\n\n- **Query builder, not ORM.** `knex(\"orders\").where({status: \"paid\"}).select(\"id\")` builds parameterized SQL. You own the mapping between rows and objects — which means no magic and no magic failures.\n- **Migrations.** Timestamped files with `up`\u002F`down` (`knex migrate:make add_orders`); `knex migrate:latest` applies. Migrations are plain code — use the schema builder or raw SQL, and always write `down`.\n- **Seeds.** `knex seed:make` + `knex seed:run` for dev\u002Ftest data; keep seeds idempotent and environment-gated.\n- **Transactions.** `knex.transaction(async (trx) => {...})` — use `trx` for every query inside. Like Sequelize, forgetting `trx` silently escapes the transaction.\n- **Connection pooling.** Knex manages the pool (`pool: { min, max }`); size per environment, set `acquireConnectionTimeout` to fail fast when saturated.\n- **Composability.** Builders are immutable-ish chainables — write helper functions that take a builder and add clauses conditionally. This is how you build dynamic filters cleanly.\n- **Raw with bindings.** `knex.raw(\"... WHERE status = ?\", [status])` for what the builder can't express; bindings keep it injection-safe.\n- **No model layer.** Row → object mapping is yours. Many teams pair Knex with Objection.js (built on Knex) for models; others keep it lean with plain functions.\n- **Dialect awareness.** The builder abstracts common SQL but each dialect has specifics (returning clauses, upsert syntax, DDL differences) — test against the real database.\n- **Streaming.** `.stream()` for processing large result sets without loading them into memory — essential for exports and batch jobs.\n- **Batch inserts.** `knex.batchInsert` (or multi-row `insert`) for bulk loads; chunk large batches to avoid parameter limits.\n- **Migrations in CI\u002FCD.** Run `migrate:latest` as a deploy step; never concurrently from multiple app instances — use a release phase or advisory lock.\n- **Query events.** Knex emits query events — hook them for logging, timing, and slow-query detection in development.\n- **Types via TS.** Knex has TypeScript support with table-type declarations; define row types once and get typed results.\n\n## Practical workflow\n\n1. **Set up knexfile.** Per-environment configs (client, connection, pool, migrations directory); connection strings from env vars, never hardcoded.\n   ```js\n   \u002F\u002F knexfile.js\n   module.exports = {\n     production: {\n       client: \"pg\",\n       connection: process.env.DATABASE_URL,\n       pool: { min: 2, max: 20, acquireTimeoutMillis: 10000 },\n       migrations: { directory: \".\u002Fmigrations\" },\n     },\n   };\n   ```\n2. **Write migrations.** `knex migrate:make add_orders`; schema builder for DDL; always implement `down`; review generated SQL for large tables (concurrent index creation).\n   ```js\n   exports.up = (knex) => knex.schema.createTable(\"orders\", (t) => {\n     t.uuid(\"id\").primary().defaultTo(knex.raw(\"gen_random_uuid()\"));\n     t.string(\"status\").notNullable().defaultTo(\"pending\");\n     t.decimal(\"total\", 10, 2).notNullable();\n     t.timestamps(true, true);\n     t.index([\"status\", \"created_at\"]);\n   });\n   exports.down = (knex) => knex.schema.dropTable(\"orders\");\n   ```\n3. **Compose queries with helpers.** Builder functions for filters\u002Fsorting\u002Fpagination shared across endpoints.\n   ```js\n   function paginate(qb, { cursor, limit = 20 }) {\n     if (cursor) qb.where(\"id\", \"\u003C\", cursor);\n     return qb.orderBy(\"id\", \"desc\").limit(limit + 1);\n   }\n   ```\n4. **Transact multi-write operations.** `trx` everywhere inside; short and ordered; retry serialization failures.\n   ```js\n   await knex.transaction(async (trx) => {\n     const [order] = await trx(\"orders\").insert({...}).returning(\"id\");\n     await trx(\"inventory\").where({...}).increment(\"reserved\", 1);\n   });\n   ```\n5. **Stream large results.** `.stream()` for exports and batch processing; never `select *` a million rows into memory.\n6. **Use raw safely.** `knex.raw` with `?` bindings for CTEs, window functions, and dialect-specific SQL — never template-literal interpolation.\n7. **Monitor queries.** Log query text + duration in dev; track slow queries in prod via the database's own tooling (pg_stat_statements).\n8. **Deploy migrations safely.** Separate release step; back up before migrating; expand-contract for zero-downtime changes on hot tables.\n\n## Common pitfalls\n\n- **Forgetting `trx`** — queries silently escaping the transaction; pass it to every query inside.\n- **String-interpolated raw SQL** — injection; always use bindings.\n- **No `down` migration** — rollbacks impossible; write both directions.\n- **Concurrent migrates** — multiple instances racing `migrate:latest`; run once per deploy.\n- **Unbounded selects** — `knex(\"orders\")` without limit on a huge table; always paginate or stream.\n- **Pool misconfiguration** — defaults under load; size min\u002Fmax and set acquire timeouts.\n- **N+1 in application code** — loops of queries instead of joins; the builder makes joins easy, use them.\n- **Loading everything into memory** — exports via `select` instead of `.stream()`; OOM on large tables.\n- **Dialect-specific SQL in shared code** — breaking other environments; isolate dialect specifics.\n- **Ignoring query logs** — slow queries invisible; log and review in development.\n- **Seeds in production** — destructive seed runs; gate by environment and keep idempotent.\n- **Huge batch inserts** — parameter limits exceeded; chunk batches (e.g., 1000 rows).\n","## Overview\n\nKnex is a SQL query builder for Node.js — not an ORM. It gives you composable, parameterized queries across Postgres, MySQL, SQLite, and MSSQL without hiding the SQL. Teams that want full control over their queries, or that find ORMs too magical, use Knex as the sane middle ground between raw SQL strings and a full object mapper.\n\nWith that control comes responsibility: there's no model layer to lean on, so schema knowledge lives in your migrations and your discipline. This skill covers Knex migrations, transaction patterns, query composition, and production configuration.\n\n## When to use\n\n- Building a Node.js data layer with explicit SQL control.\n- Writing and organizing Knex migrations and seeds.\n- Composing dynamic queries (filters, sorting, pagination).\n- Managing transactions correctly in Knex.\n- Choosing between Knex, an ORM, and raw SQL.\n- Using Knex with Objection.js as a model layer on top.\n- Tuning connection pools for production.\n\n## Core concepts\n\n- **Query builder, not ORM.** `knex(\"orders\").where({status: \"paid\"}).select(\"id\")` builds parameterized SQL. You own the mapping between rows and objects — which means no magic and no magic failures.\n- **Migrations.** Timestamped files with `up`\u002F`down` (`knex migrate:make add_orders`); `knex migrate:latest` applies. Migrations are plain code — use the schema builder or raw SQL, and always write `down`.\n- **Seeds.** `knex seed:make` + `knex seed:run` for dev\u002Ftest data; keep seeds idempotent and environment-gated.\n- **Transactions.** `knex.transaction(async (trx) => {...})` — use `trx` for every query inside. Like Sequelize, forgetting `trx` silently escapes the transaction.\n- **Connection pooling.** Knex manages the pool (`pool: { min, max }`); size per environment, set `acquireConnectionTimeout` to fail fast when saturated.\n- **Composability.** Builders are immutable-ish chainables — write helper functions that take a builder and add clauses conditionally. This is how you build dynamic filters cleanly.\n- **Raw with bindings.** `knex.raw(\"... WHERE status = ?\", [status])` for what the builder can't express; bindings keep it injection-safe.\n- **No model layer.** Row → object mapping is yours. Many teams pair Knex with Objection.js (built on Knex) for models; others keep it lean with plain functions.\n- **Dialect awareness.** The builder abstracts common SQL but each dialect has specifics (returning clauses, upsert syntax, DDL differences) — test against the real database.\n- **Streaming.** `.stream()` for processing large result sets without loading them into memory — essential for exports and batch jobs.\n- **Batch inserts.** `knex.batchInsert` (or multi-row `insert`) for bulk loads; chunk large batches to avoid parameter limits.\n- **Migrations in CI\u002FCD.** Run `migrate:latest` as a deploy step; never concurrently from multiple app instances — use a release phase or advisory lock.\n- **Query events.** Knex emits query events — hook them for logging, timing, and slow-query detection in development.\n- **Types via TS.** Knex has TypeScript support with table-type declarations; define row types once and get typed results.\n\n## Practical workflow\n\n1. **Set up knexfile.** Per-environment configs (client, connection, pool, migrations directory); connection strings from env vars, never hardcoded.\n   ```js\n   \u002F\u002F knexfile.js\n   module.exports = {\n     production: {\n       client: \"pg\",\n       connection: process.env.DATABASE_URL,\n       pool: { min: 2, max: 20, acquireTimeoutMillis: 10000 },\n       migrations: { directory: \".\u002Fmigrations\" },\n     },\n   };\n   ```\n2. **Write migrations.** `knex migrate:make add_orders`; schema builder for DDL; always implement `down`; review generated SQL for large tables (concurrent index creation).\n   ```js\n   exports.up = (knex) => knex.schema.createTable(\"orders\", (t) => {\n     t.uuid(\"id\").primary().defaultTo(knex.raw(\"gen_random_uuid()\"));\n     t.string(\"status\").notNullable().defaultTo(\"pending\");\n     t.decimal(\"total\", 10, 2).notNullable();\n     t.timestamps(true, true);\n     t.index([\"status\", \"created_at\"]);\n   });\n   exports.down = (knex) => knex.schema.dropTable(\"orders\");\n   ```\n3. **Compose queries with helpers.** Builder functions for filters\u002Fsorting\u002Fpagination shared across endpoints.\n   ```js\n   function paginate(qb, { cursor, limit = 20 }) {\n     if (cursor) qb.where(\"id\", \"\u003C\", cursor);\n     return qb.orderBy(\"id\", \"desc\").limit(limit + 1);\n   }\n   ```\n4. **Transact multi-write operations.** `trx` everywhere inside; short and ordered; retry serialization failures.\n   ```js\n   await knex.transaction(async (trx) => {\n     const [order] = await trx(\"orders\").insert({...}).returning(\"id\");\n     await trx(\"inventory\").where({...}).increment(\"reserved\", 1);\n   });\n   ```\n5. **Stream large results.** `.stream()` for exports and batch processing; never `select *` a million rows into memory.\n6. **Use raw safely.** `knex.raw` with `?` bindings for CTEs, window functions, and dialect-specific SQL — never template-literal interpolation.\n7. **Monitor queries.** Log query text + duration in dev; track slow queries in prod via the database's own tooling (pg_stat_statements).\n8. **Deploy migrations safely.** Separate release step; back up before migrating; expand-contract for zero-downtime changes on hot tables.\n\n## Common pitfalls\n\n- **Forgetting `trx`** — queries silently escaping the transaction; pass it to every query inside.\n- **String-interpolated raw SQL** — injection; always use bindings.\n- **No `down` migration** — rollbacks impossible; write both directions.\n- **Concurrent migrates** — multiple instances racing `migrate:latest`; run once per deploy.\n- **Unbounded selects** — `knex(\"orders\")` without limit on a huge table; always paginate or stream.\n- **Pool misconfiguration** — defaults under load; size min\u002Fmax and set acquire timeouts.\n- **N+1 in application code** — loops of queries instead of joins; the builder makes joins easy, use them.\n- **Loading everything into memory** — exports via `select` instead of `.stream()`; OOM on large tables.\n- **Dialect-specific SQL in shared code** — breaking other environments; isolate dialect specifics.\n- **Ignoring query logs** — slow queries invisible; log and review in development.\n- **Seeds in production** — destructive seed runs; gate by environment and keep idempotent.\n- **Huge batch inserts** — parameter limits exceeded; chunk batches (e.g., 1000 rows).\n",{"name":5,"category":24,"description":7},"development","main","af388a77c2fe5e0b4fd879cca4300a0ffa9a6579","skills\u002Fams-knex-pro",1,"https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis","https:\u002F\u002Fgithub.com\u002FTanNhatCMS","https:\u002F\u002Fmrkiet.name.vn","2026-11-07 14:23:08",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add TanNhatCMS\u002Fjarvis --skill knex-pro",{"tool":39,"command":40},"bunx","bunx skills add TanNhatCMS\u002Fjarvis --skill knex-pro",{"tool":42,"command":43},"pnpm","pnpm dlx skills add TanNhatCMS\u002Fjarvis --skill knex-pro","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fams-knex-pro\u002FSKILL.md",true,[],[48,55,63,70,77,84],{"skillNo":49,"name":50,"nameZh":6,"description":51,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":52,"categories":53,"keywords":54,"publishedAt":19},"01M7EWYJR0J8DARY7E59Z6Y9MV","web-scrape","Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open\u002Ffetch fails on JS-heavy pages, or when you need clean markdown\u002Fstructured extraction from a site. Requires FIRECRAWL_API_KEY.","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fweb-scrape\u002FSKILL.md",[],[],{"skillNo":56,"name":57,"nameZh":6,"description":58,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":59,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":19},"01M7EWYBN5P6F2AJG3FR24T9BP","design-taste-frontend","tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML\u002FCSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, \"AI-made\", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Ftaste-design\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Ftaste-design\u002FSKILL.md",[],[],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":19},"01M7EWY8FQFNQ2GB7NZZWGSSDX","test-driven-development","Use when implementing any feature or bugfix, before writing implementation code","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fsuperpowers-tdd\u002FSKILL.md",[],[],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M7EWY5SHBFRH1HDHVWM9K7TV","systematic-debugging","Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fsuperpowers-debugging\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":19},"01M7EWY3NM0Z0JAKS7HDZ24K66","requesting-code-review","Use when completing tasks, implementing major features, or before merging to verify work meets requirements","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fsuperpowers-code-review\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":19},"01M7EWY0WRMWX4M9ZFY0WKC593","brainstorming","You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fsuperpowers-brainstorming\u002FSKILL.md",[],[]]