jorgex-stack 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/PRD.md +297 -297
  2. package/README.md +56 -56
  3. package/dist/cli.js +7 -2
  4. package/package.json +1 -1
  5. package/stack/agents/orchestrator.md +192 -192
  6. package/stack/agents/tester.md +71 -71
  7. package/stack/commands/xreview.md +80 -80
  8. package/stack/hooks/hooks.json +18 -18
  9. package/stack/scripts/post-pr-review.cjs +156 -156
  10. package/stack/skills/diagnose/SKILL.md +117 -117
  11. package/stack/skills/diagnose/scripts/hitl-loop.template.sh +41 -41
  12. package/stack/skills/find-skills/SKILL.md +133 -133
  13. package/stack/skills/mcp-builder/LICENSE.txt +201 -201
  14. package/stack/skills/mcp-builder/SKILL.md +236 -236
  15. package/stack/skills/mcp-builder/reference/evaluation.md +601 -601
  16. package/stack/skills/mcp-builder/reference/mcp_best_practices.md +249 -249
  17. package/stack/skills/mcp-builder/reference/node_mcp_server.md +969 -969
  18. package/stack/skills/mcp-builder/reference/python_mcp_server.md +718 -718
  19. package/stack/skills/mcp-builder/scripts/connections.py +151 -151
  20. package/stack/skills/mcp-builder/scripts/evaluation.py +373 -373
  21. package/stack/skills/mcp-builder/scripts/example_evaluation.xml +22 -22
  22. package/stack/skills/mcp-builder/scripts/requirements.txt +2 -2
  23. package/stack/skills/obsidian-cli/SKILL.md +106 -106
  24. package/stack/skills/obsidian-markdown/SKILL.md +196 -196
  25. package/stack/skills/obsidian-markdown/references/CALLOUTS.md +58 -58
  26. package/stack/skills/obsidian-markdown/references/EMBEDS.md +63 -63
  27. package/stack/skills/obsidian-markdown/references/PROPERTIES.md +61 -61
  28. package/stack/skills/react-doctor/SKILL.md +19 -19
  29. package/stack/skills/skill-creator/LICENSE.txt +201 -201
  30. package/stack/skills/skill-creator/agents/analyzer.md +274 -274
  31. package/stack/skills/skill-creator/agents/comparator.md +202 -202
  32. package/stack/skills/skill-creator/agents/grader.md +223 -223
  33. package/stack/skills/skill-creator/assets/eval_review.html +146 -146
  34. package/stack/skills/skill-creator/eval-viewer/generate_review.py +471 -471
  35. package/stack/skills/skill-creator/eval-viewer/viewer.html +1325 -1325
  36. package/stack/skills/skill-creator/references/schemas.md +430 -430
  37. package/stack/skills/skill-creator/scripts/aggregate_benchmark.py +401 -401
  38. package/stack/skills/skill-creator/scripts/generate_report.py +326 -326
  39. package/stack/skills/skill-creator/scripts/improve_description.py +248 -248
  40. package/stack/skills/skill-creator/scripts/package_skill.py +136 -136
  41. package/stack/skills/skill-creator/scripts/quick_validate.py +102 -102
  42. package/stack/skills/skill-creator/scripts/run_eval.py +310 -310
  43. package/stack/skills/skill-creator/scripts/run_loop.py +332 -332
  44. package/stack/skills/skill-creator/scripts/utils.py +47 -47
  45. package/stack/skills/supabase/SKILL.md +135 -135
  46. package/stack/skills/supabase/assets/feedback-issue-template.md +17 -17
  47. package/stack/skills/supabase/references/skill-feedback.md +17 -17
  48. package/stack/skills/supabase-postgres-best-practices/SKILL.md +64 -64
  49. package/stack/skills/supabase-postgres-best-practices/references/_contributing.md +170 -170
  50. package/stack/skills/supabase-postgres-best-practices/references/_sections.md +39 -39
  51. package/stack/skills/supabase-postgres-best-practices/references/_template.md +34 -34
  52. package/stack/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -55
  53. package/stack/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -49
  54. package/stack/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -46
  55. package/stack/skills/supabase-postgres-best-practices/references/conn-limits.md +44 -44
  56. package/stack/skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -41
  57. package/stack/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -46
  58. package/stack/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -54
  59. package/stack/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -53
  60. package/stack/skills/supabase-postgres-best-practices/references/data-pagination.md +50 -50
  61. package/stack/skills/supabase-postgres-best-practices/references/data-upsert.md +50 -50
  62. package/stack/skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -56
  63. package/stack/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -68
  64. package/stack/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -50
  65. package/stack/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -54
  66. package/stack/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -45
  67. package/stack/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -55
  68. package/stack/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -55
  69. package/stack/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -44
  70. package/stack/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -40
  71. package/stack/skills/supabase-postgres-best-practices/references/query-index-types.md +48 -48
  72. package/stack/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -43
  73. package/stack/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -45
  74. package/stack/skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -80
  75. package/stack/skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -46
  76. package/stack/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -59
  77. package/stack/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -55
  78. package/stack/skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -55
  79. package/stack/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -61
  80. package/stack/skills/supabase-postgres-best-practices/references/security-privileges.md +54 -54
  81. package/stack/skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -50
  82. package/stack/skills/supabase-postgres-best-practices/references/security-rls-performance.md +63 -63
  83. package/stack/skills/tdd/SKILL.md +109 -109
  84. package/stack/skills/tdd/deep-modules.md +33 -33
  85. package/stack/skills/tdd/interface-design.md +31 -31
  86. package/stack/skills/tdd/mocking.md +59 -59
  87. package/stack/skills/tdd/refactoring.md +10 -10
  88. package/stack/skills/tdd/tests.md +61 -61
  89. package/stack/skills/to-issues/SKILL.md +83 -83
  90. package/stack/skills/to-prd/SKILL.md +72 -72
  91. package/upstreams.json +96 -96
@@ -1,49 +1,49 @@
1
- ---
2
- title: Index JSONB Columns for Efficient Querying
3
- impact: MEDIUM
4
- impactDescription: 10-100x faster JSONB queries with proper indexing
5
- tags: jsonb, gin, indexes, json
6
- ---
7
-
8
- ## Index JSONB Columns for Efficient Querying
9
-
10
- JSONB queries without indexes scan the entire table. Use GIN indexes for containment queries.
11
-
12
- **Incorrect (no index on JSONB):**
13
-
14
- ```sql
15
- create table products (
16
- id bigint primary key,
17
- attributes jsonb
18
- );
19
-
20
- -- Full table scan for every query
21
- select * from products where attributes @> '{"color": "red"}';
22
- select * from products where attributes->>'brand' = 'Nike';
23
- ```
24
-
25
- **Correct (GIN index for JSONB):**
26
-
27
- ```sql
28
- -- GIN index for containment operators (@>, ?, ?&, ?|)
29
- create index products_attrs_gin on products using gin (attributes);
30
-
31
- -- Now containment queries use the index
32
- select * from products where attributes @> '{"color": "red"}';
33
-
34
- -- For specific key lookups, use expression index
35
- create index products_brand_idx on products ((attributes->>'brand'));
36
- select * from products where attributes->>'brand' = 'Nike';
37
- ```
38
-
39
- Choose the right operator class:
40
-
41
- ```sql
42
- -- jsonb_ops (default): supports all operators, larger index
43
- create index idx1 on products using gin (attributes);
44
-
45
- -- jsonb_path_ops: only @> operator, but 2-3x smaller index
46
- create index idx2 on products using gin (attributes jsonb_path_ops);
47
- ```
48
-
49
- Reference: [JSONB Indexes](https://www.postgresql.org/docs/current/datatype-json.html#JSON-INDEXING)
1
+ ---
2
+ title: Index JSONB Columns for Efficient Querying
3
+ impact: MEDIUM
4
+ impactDescription: 10-100x faster JSONB queries with proper indexing
5
+ tags: jsonb, gin, indexes, json
6
+ ---
7
+
8
+ ## Index JSONB Columns for Efficient Querying
9
+
10
+ JSONB queries without indexes scan the entire table. Use GIN indexes for containment queries.
11
+
12
+ **Incorrect (no index on JSONB):**
13
+
14
+ ```sql
15
+ create table products (
16
+ id bigint primary key,
17
+ attributes jsonb
18
+ );
19
+
20
+ -- Full table scan for every query
21
+ select * from products where attributes @> '{"color": "red"}';
22
+ select * from products where attributes->>'brand' = 'Nike';
23
+ ```
24
+
25
+ **Correct (GIN index for JSONB):**
26
+
27
+ ```sql
28
+ -- GIN index for containment operators (@>, ?, ?&, ?|)
29
+ create index products_attrs_gin on products using gin (attributes);
30
+
31
+ -- Now containment queries use the index
32
+ select * from products where attributes @> '{"color": "red"}';
33
+
34
+ -- For specific key lookups, use expression index
35
+ create index products_brand_idx on products ((attributes->>'brand'));
36
+ select * from products where attributes->>'brand' = 'Nike';
37
+ ```
38
+
39
+ Choose the right operator class:
40
+
41
+ ```sql
42
+ -- jsonb_ops (default): supports all operators, larger index
43
+ create index idx1 on products using gin (attributes);
44
+
45
+ -- jsonb_path_ops: only @> operator, but 2-3x smaller index
46
+ create index idx2 on products using gin (attributes jsonb_path_ops);
47
+ ```
48
+
49
+ Reference: [JSONB Indexes](https://www.postgresql.org/docs/current/datatype-json.html#JSON-INDEXING)
@@ -1,46 +1,46 @@
1
- ---
2
- title: Configure Idle Connection Timeouts
3
- impact: HIGH
4
- impactDescription: Reclaim 30-50% of connection slots from idle clients
5
- tags: connections, timeout, idle, resource-management
6
- ---
7
-
8
- ## Configure Idle Connection Timeouts
9
-
10
- Idle connections waste resources. Configure timeouts to automatically reclaim them.
11
-
12
- **Incorrect (connections held indefinitely):**
13
-
14
- ```sql
15
- -- No timeout configured
16
- show idle_in_transaction_session_timeout; -- 0 (disabled)
17
-
18
- -- Connections stay open forever, even when idle
19
- select pid, state, state_change, query
20
- from pg_stat_activity
21
- where state = 'idle in transaction';
22
- -- Shows transactions idle for hours, holding locks
23
- ```
24
-
25
- **Correct (automatic cleanup of idle connections):**
26
-
27
- ```sql
28
- -- Terminate connections idle in transaction after 30 seconds
29
- alter system set idle_in_transaction_session_timeout = '30s';
30
-
31
- -- Terminate completely idle connections after 10 minutes
32
- alter system set idle_session_timeout = '10min';
33
-
34
- -- Reload configuration
35
- select pg_reload_conf();
36
- ```
37
-
38
- For pooled connections, configure at the pooler level:
39
-
40
- ```ini
41
- # pgbouncer.ini
42
- server_idle_timeout = 60
43
- client_idle_timeout = 300
44
- ```
45
-
46
- Reference: [Connection Timeouts](https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-IDLE-IN-TRANSACTION-SESSION-TIMEOUT)
1
+ ---
2
+ title: Configure Idle Connection Timeouts
3
+ impact: HIGH
4
+ impactDescription: Reclaim 30-50% of connection slots from idle clients
5
+ tags: connections, timeout, idle, resource-management
6
+ ---
7
+
8
+ ## Configure Idle Connection Timeouts
9
+
10
+ Idle connections waste resources. Configure timeouts to automatically reclaim them.
11
+
12
+ **Incorrect (connections held indefinitely):**
13
+
14
+ ```sql
15
+ -- No timeout configured
16
+ show idle_in_transaction_session_timeout; -- 0 (disabled)
17
+
18
+ -- Connections stay open forever, even when idle
19
+ select pid, state, state_change, query
20
+ from pg_stat_activity
21
+ where state = 'idle in transaction';
22
+ -- Shows transactions idle for hours, holding locks
23
+ ```
24
+
25
+ **Correct (automatic cleanup of idle connections):**
26
+
27
+ ```sql
28
+ -- Terminate connections idle in transaction after 30 seconds
29
+ alter system set idle_in_transaction_session_timeout = '30s';
30
+
31
+ -- Terminate completely idle connections after 10 minutes
32
+ alter system set idle_session_timeout = '10min';
33
+
34
+ -- Reload configuration
35
+ select pg_reload_conf();
36
+ ```
37
+
38
+ For pooled connections, configure at the pooler level:
39
+
40
+ ```ini
41
+ # pgbouncer.ini
42
+ server_idle_timeout = 60
43
+ client_idle_timeout = 300
44
+ ```
45
+
46
+ Reference: [Connection Timeouts](https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-IDLE-IN-TRANSACTION-SESSION-TIMEOUT)
@@ -1,44 +1,44 @@
1
- ---
2
- title: Set Appropriate Connection Limits
3
- impact: CRITICAL
4
- impactDescription: Prevent database crashes and memory exhaustion
5
- tags: connections, max-connections, limits, stability
6
- ---
7
-
8
- ## Set Appropriate Connection Limits
9
-
10
- Too many connections exhaust memory and degrade performance. Set limits based on available resources.
11
-
12
- **Incorrect (unlimited or excessive connections):**
13
-
14
- ```sql
15
- -- Default max_connections = 100, but often increased blindly
16
- show max_connections; -- 500 (way too high for 4GB RAM)
17
-
18
- -- Each connection uses 1-3MB RAM
19
- -- 500 connections * 2MB = 1GB just for connections!
20
- -- Out of memory errors under load
21
- ```
22
-
23
- **Correct (calculate based on resources):**
24
-
25
- ```sql
26
- -- Formula: max_connections = (RAM in MB / 5MB per connection) - reserved
27
- -- For 4GB RAM: (4096 / 5) - 10 = ~800 theoretical max
28
- -- But practically, 100-200 is better for query performance
29
-
30
- -- Recommended settings for 4GB RAM
31
- alter system set max_connections = 100;
32
-
33
- -- Also set work_mem appropriately
34
- -- work_mem * max_connections should not exceed 25% of RAM
35
- alter system set work_mem = '8MB'; -- 8MB * 100 = 800MB max
36
- ```
37
-
38
- Monitor connection usage:
39
-
40
- ```sql
41
- select count(*), state from pg_stat_activity group by state;
42
- ```
43
-
44
- Reference: [Database Connections](https://supabase.com/docs/guides/platform/performance#connection-management)
1
+ ---
2
+ title: Set Appropriate Connection Limits
3
+ impact: CRITICAL
4
+ impactDescription: Prevent database crashes and memory exhaustion
5
+ tags: connections, max-connections, limits, stability
6
+ ---
7
+
8
+ ## Set Appropriate Connection Limits
9
+
10
+ Too many connections exhaust memory and degrade performance. Set limits based on available resources.
11
+
12
+ **Incorrect (unlimited or excessive connections):**
13
+
14
+ ```sql
15
+ -- Default max_connections = 100, but often increased blindly
16
+ show max_connections; -- 500 (way too high for 4GB RAM)
17
+
18
+ -- Each connection uses 1-3MB RAM
19
+ -- 500 connections * 2MB = 1GB just for connections!
20
+ -- Out of memory errors under load
21
+ ```
22
+
23
+ **Correct (calculate based on resources):**
24
+
25
+ ```sql
26
+ -- Formula: max_connections = (RAM in MB / 5MB per connection) - reserved
27
+ -- For 4GB RAM: (4096 / 5) - 10 = ~800 theoretical max
28
+ -- But practically, 100-200 is better for query performance
29
+
30
+ -- Recommended settings for 4GB RAM
31
+ alter system set max_connections = 100;
32
+
33
+ -- Also set work_mem appropriately
34
+ -- work_mem * max_connections should not exceed 25% of RAM
35
+ alter system set work_mem = '8MB'; -- 8MB * 100 = 800MB max
36
+ ```
37
+
38
+ Monitor connection usage:
39
+
40
+ ```sql
41
+ select count(*), state from pg_stat_activity group by state;
42
+ ```
43
+
44
+ Reference: [Database Connections](https://supabase.com/docs/guides/platform/performance#connection-management)
@@ -1,41 +1,41 @@
1
- ---
2
- title: Use Connection Pooling for All Applications
3
- impact: CRITICAL
4
- impactDescription: Handle 10-100x more concurrent users
5
- tags: connection-pooling, pgbouncer, performance, scalability
6
- ---
7
-
8
- ## Use Connection Pooling for All Applications
9
-
10
- Postgres connections are expensive (1-3MB RAM each). Without pooling, applications exhaust connections under load.
11
-
12
- **Incorrect (new connection per request):**
13
-
14
- ```sql
15
- -- Each request creates a new connection
16
- -- Application code: db.connect() per request
17
- -- Result: 500 concurrent users = 500 connections = crashed database
18
-
19
- -- Check current connections
20
- select count(*) from pg_stat_activity; -- 487 connections!
21
- ```
22
-
23
- **Correct (connection pooling):**
24
-
25
- ```sql
26
- -- Use a pooler like PgBouncer between app and database
27
- -- Application connects to pooler, pooler reuses a small pool to Postgres
28
-
29
- -- Configure pool_size based on: (CPU cores * 2) + spindle_count
30
- -- Example for 4 cores: pool_size = 10
31
-
32
- -- Result: 500 concurrent users share 10 actual connections
33
- select count(*) from pg_stat_activity; -- 10 connections
34
- ```
35
-
36
- Pool modes:
37
-
38
- - **Transaction mode**: connection returned after each transaction (best for most apps)
39
- - **Session mode**: connection held for entire session (needed for prepared statements, temp tables)
40
-
41
- Reference: [Connection Pooling](https://supabase.com/docs/guides/database/connecting-to-postgres#connection-pooler)
1
+ ---
2
+ title: Use Connection Pooling for All Applications
3
+ impact: CRITICAL
4
+ impactDescription: Handle 10-100x more concurrent users
5
+ tags: connection-pooling, pgbouncer, performance, scalability
6
+ ---
7
+
8
+ ## Use Connection Pooling for All Applications
9
+
10
+ Postgres connections are expensive (1-3MB RAM each). Without pooling, applications exhaust connections under load.
11
+
12
+ **Incorrect (new connection per request):**
13
+
14
+ ```sql
15
+ -- Each request creates a new connection
16
+ -- Application code: db.connect() per request
17
+ -- Result: 500 concurrent users = 500 connections = crashed database
18
+
19
+ -- Check current connections
20
+ select count(*) from pg_stat_activity; -- 487 connections!
21
+ ```
22
+
23
+ **Correct (connection pooling):**
24
+
25
+ ```sql
26
+ -- Use a pooler like PgBouncer between app and database
27
+ -- Application connects to pooler, pooler reuses a small pool to Postgres
28
+
29
+ -- Configure pool_size based on: (CPU cores * 2) + spindle_count
30
+ -- Example for 4 cores: pool_size = 10
31
+
32
+ -- Result: 500 concurrent users share 10 actual connections
33
+ select count(*) from pg_stat_activity; -- 10 connections
34
+ ```
35
+
36
+ Pool modes:
37
+
38
+ - **Transaction mode**: connection returned after each transaction (best for most apps)
39
+ - **Session mode**: connection held for entire session (needed for prepared statements, temp tables)
40
+
41
+ Reference: [Connection Pooling](https://supabase.com/docs/guides/database/connecting-to-postgres#connection-pooler)
@@ -1,46 +1,46 @@
1
- ---
2
- title: Use Prepared Statements Correctly with Pooling
3
- impact: HIGH
4
- impactDescription: Avoid prepared statement conflicts in pooled environments
5
- tags: prepared-statements, connection-pooling, transaction-mode
6
- ---
7
-
8
- ## Use Prepared Statements Correctly with Pooling
9
-
10
- Prepared statements are tied to individual database connections. In transaction-mode pooling, connections are shared, causing conflicts.
11
-
12
- **Incorrect (named prepared statements with transaction pooling):**
13
-
14
- ```sql
15
- -- Named prepared statement
16
- prepare get_user as select * from users where id = $1;
17
-
18
- -- In transaction mode pooling, next request may get different connection
19
- execute get_user(123);
20
- -- ERROR: prepared statement "get_user" does not exist
21
- ```
22
-
23
- **Correct (use unnamed statements or session mode):**
24
-
25
- ```sql
26
- -- Option 1: Use unnamed prepared statements (most ORMs do this automatically)
27
- -- The query is prepared and executed in a single protocol message
28
-
29
- -- Option 2: Deallocate after use in transaction mode
30
- prepare get_user as select * from users where id = $1;
31
- execute get_user(123);
32
- deallocate get_user;
33
-
34
- -- Option 3: Use session mode pooling (port 5432 vs 6543)
35
- -- Connection is held for entire session, prepared statements persist
36
- ```
37
-
38
- Check your driver settings:
39
-
40
- ```sql
41
- -- Many drivers use prepared statements by default
42
- -- Node.js pg: { prepare: false } to disable
43
- -- JDBC: prepareThreshold=0 to disable
44
- ```
45
-
46
- Reference: [Prepared Statements with Pooling](https://supabase.com/docs/guides/database/connecting-to-postgres#connection-pool-modes)
1
+ ---
2
+ title: Use Prepared Statements Correctly with Pooling
3
+ impact: HIGH
4
+ impactDescription: Avoid prepared statement conflicts in pooled environments
5
+ tags: prepared-statements, connection-pooling, transaction-mode
6
+ ---
7
+
8
+ ## Use Prepared Statements Correctly with Pooling
9
+
10
+ Prepared statements are tied to individual database connections. In transaction-mode pooling, connections are shared, causing conflicts.
11
+
12
+ **Incorrect (named prepared statements with transaction pooling):**
13
+
14
+ ```sql
15
+ -- Named prepared statement
16
+ prepare get_user as select * from users where id = $1;
17
+
18
+ -- In transaction mode pooling, next request may get different connection
19
+ execute get_user(123);
20
+ -- ERROR: prepared statement "get_user" does not exist
21
+ ```
22
+
23
+ **Correct (use unnamed statements or session mode):**
24
+
25
+ ```sql
26
+ -- Option 1: Use unnamed prepared statements (most ORMs do this automatically)
27
+ -- The query is prepared and executed in a single protocol message
28
+
29
+ -- Option 2: Deallocate after use in transaction mode
30
+ prepare get_user as select * from users where id = $1;
31
+ execute get_user(123);
32
+ deallocate get_user;
33
+
34
+ -- Option 3: Use session mode pooling (port 5432 vs 6543)
35
+ -- Connection is held for entire session, prepared statements persist
36
+ ```
37
+
38
+ Check your driver settings:
39
+
40
+ ```sql
41
+ -- Many drivers use prepared statements by default
42
+ -- Node.js pg: { prepare: false } to disable
43
+ -- JDBC: prepareThreshold=0 to disable
44
+ ```
45
+
46
+ Reference: [Prepared Statements with Pooling](https://supabase.com/docs/guides/database/connecting-to-postgres#connection-pool-modes)
@@ -1,54 +1,54 @@
1
- ---
2
- title: Batch INSERT Statements for Bulk Data
3
- impact: MEDIUM
4
- impactDescription: 10-50x faster bulk inserts
5
- tags: batch, insert, bulk, performance, copy
6
- ---
7
-
8
- ## Batch INSERT Statements for Bulk Data
9
-
10
- Individual INSERT statements have high overhead. Batch multiple rows in single statements or use COPY.
11
-
12
- **Incorrect (individual inserts):**
13
-
14
- ```sql
15
- -- Each insert is a separate transaction and round trip
16
- insert into events (user_id, action) values (1, 'click');
17
- insert into events (user_id, action) values (1, 'view');
18
- insert into events (user_id, action) values (2, 'click');
19
- -- ... 1000 more individual inserts
20
-
21
- -- 1000 inserts = 1000 round trips = slow
22
- ```
23
-
24
- **Correct (batch insert):**
25
-
26
- ```sql
27
- -- Multiple rows in single statement
28
- insert into events (user_id, action) values
29
- (1, 'click'),
30
- (1, 'view'),
31
- (2, 'click'),
32
- -- ... up to ~1000 rows per batch
33
- (999, 'view');
34
-
35
- -- One round trip for 1000 rows
36
- ```
37
-
38
- For large imports, use COPY:
39
-
40
- ```sql
41
- -- COPY is fastest for bulk loading
42
- copy events (user_id, action, created_at)
43
- from '/path/to/data.csv'
44
- with (format csv, header true);
45
-
46
- -- Or from stdin in application
47
- copy events (user_id, action) from stdin with (format csv);
48
- 1,click
49
- 1,view
50
- 2,click
51
- \.
52
- ```
53
-
54
- Reference: [COPY](https://www.postgresql.org/docs/current/sql-copy.html)
1
+ ---
2
+ title: Batch INSERT Statements for Bulk Data
3
+ impact: MEDIUM
4
+ impactDescription: 10-50x faster bulk inserts
5
+ tags: batch, insert, bulk, performance, copy
6
+ ---
7
+
8
+ ## Batch INSERT Statements for Bulk Data
9
+
10
+ Individual INSERT statements have high overhead. Batch multiple rows in single statements or use COPY.
11
+
12
+ **Incorrect (individual inserts):**
13
+
14
+ ```sql
15
+ -- Each insert is a separate transaction and round trip
16
+ insert into events (user_id, action) values (1, 'click');
17
+ insert into events (user_id, action) values (1, 'view');
18
+ insert into events (user_id, action) values (2, 'click');
19
+ -- ... 1000 more individual inserts
20
+
21
+ -- 1000 inserts = 1000 round trips = slow
22
+ ```
23
+
24
+ **Correct (batch insert):**
25
+
26
+ ```sql
27
+ -- Multiple rows in single statement
28
+ insert into events (user_id, action) values
29
+ (1, 'click'),
30
+ (1, 'view'),
31
+ (2, 'click'),
32
+ -- ... up to ~1000 rows per batch
33
+ (999, 'view');
34
+
35
+ -- One round trip for 1000 rows
36
+ ```
37
+
38
+ For large imports, use COPY:
39
+
40
+ ```sql
41
+ -- COPY is fastest for bulk loading
42
+ copy events (user_id, action, created_at)
43
+ from '/path/to/data.csv'
44
+ with (format csv, header true);
45
+
46
+ -- Or from stdin in application
47
+ copy events (user_id, action) from stdin with (format csv);
48
+ 1,click
49
+ 1,view
50
+ 2,click
51
+ \.
52
+ ```
53
+
54
+ Reference: [COPY](https://www.postgresql.org/docs/current/sql-copy.html)
@@ -1,53 +1,53 @@
1
- ---
2
- title: Eliminate N+1 Queries with Batch Loading
3
- impact: MEDIUM-HIGH
4
- impactDescription: 10-100x fewer database round trips
5
- tags: n-plus-one, batch, performance, queries
6
- ---
7
-
8
- ## Eliminate N+1 Queries with Batch Loading
9
-
10
- N+1 queries execute one query per item in a loop. Batch them into a single query using arrays or JOINs.
11
-
12
- **Incorrect (N+1 queries):**
13
-
14
- ```sql
15
- -- First query: get all users
16
- select id from users where active = true; -- Returns 100 IDs
17
-
18
- -- Then N queries, one per user
19
- select * from orders where user_id = 1;
20
- select * from orders where user_id = 2;
21
- select * from orders where user_id = 3;
22
- -- ... 97 more queries!
23
-
24
- -- Total: 101 round trips to database
25
- ```
26
-
27
- **Correct (single batch query):**
28
-
29
- ```sql
30
- -- Collect IDs and query once with ANY
31
- select * from orders where user_id = any(array[1, 2, 3, ...]);
32
-
33
- -- Or use JOIN instead of loop
34
- select u.id, u.name, o.*
35
- from users u
36
- left join orders o on o.user_id = u.id
37
- where u.active = true;
38
-
39
- -- Total: 1 round trip
40
- ```
41
-
42
- Application pattern:
43
-
44
- ```sql
45
- -- Instead of looping in application code:
46
- -- for user in users: db.query("SELECT * FROM orders WHERE user_id = $1", user.id)
47
-
48
- -- Pass array parameter:
49
- select * from orders where user_id = any($1::bigint[]);
50
- -- Application passes: [1, 2, 3, 4, 5, ...]
51
- ```
52
-
53
- Reference: [N+1 Query Problem](https://supabase.com/docs/guides/database/query-optimization)
1
+ ---
2
+ title: Eliminate N+1 Queries with Batch Loading
3
+ impact: MEDIUM-HIGH
4
+ impactDescription: 10-100x fewer database round trips
5
+ tags: n-plus-one, batch, performance, queries
6
+ ---
7
+
8
+ ## Eliminate N+1 Queries with Batch Loading
9
+
10
+ N+1 queries execute one query per item in a loop. Batch them into a single query using arrays or JOINs.
11
+
12
+ **Incorrect (N+1 queries):**
13
+
14
+ ```sql
15
+ -- First query: get all users
16
+ select id from users where active = true; -- Returns 100 IDs
17
+
18
+ -- Then N queries, one per user
19
+ select * from orders where user_id = 1;
20
+ select * from orders where user_id = 2;
21
+ select * from orders where user_id = 3;
22
+ -- ... 97 more queries!
23
+
24
+ -- Total: 101 round trips to database
25
+ ```
26
+
27
+ **Correct (single batch query):**
28
+
29
+ ```sql
30
+ -- Collect IDs and query once with ANY
31
+ select * from orders where user_id = any(array[1, 2, 3, ...]);
32
+
33
+ -- Or use JOIN instead of loop
34
+ select u.id, u.name, o.*
35
+ from users u
36
+ left join orders o on o.user_id = u.id
37
+ where u.active = true;
38
+
39
+ -- Total: 1 round trip
40
+ ```
41
+
42
+ Application pattern:
43
+
44
+ ```sql
45
+ -- Instead of looping in application code:
46
+ -- for user in users: db.query("SELECT * FROM orders WHERE user_id = $1", user.id)
47
+
48
+ -- Pass array parameter:
49
+ select * from orders where user_id = any($1::bigint[]);
50
+ -- Application passes: [1, 2, 3, 4, 5, ...]
51
+ ```
52
+
53
+ Reference: [N+1 Query Problem](https://supabase.com/docs/guides/database/query-optimization)