forge-sql-orm 2.0.17 → 2.0.19

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 (41) hide show
  1. package/README.md +95 -4
  2. package/dist/ForgeSQLORM.js +382 -60
  3. package/dist/ForgeSQLORM.js.map +1 -1
  4. package/dist/ForgeSQLORM.mjs +382 -60
  5. package/dist/ForgeSQLORM.mjs.map +1 -1
  6. package/dist/core/ForgeSQLAnalyseOperations.d.ts +250 -0
  7. package/dist/core/ForgeSQLAnalyseOperations.d.ts.map +1 -0
  8. package/dist/core/ForgeSQLCrudOperations.d.ts +1 -1
  9. package/dist/core/ForgeSQLCrudOperations.d.ts.map +1 -1
  10. package/dist/core/ForgeSQLORM.d.ts +12 -2
  11. package/dist/core/ForgeSQLORM.d.ts.map +1 -1
  12. package/dist/core/ForgeSQLQueryBuilder.d.ts +112 -21
  13. package/dist/core/ForgeSQLQueryBuilder.d.ts.map +1 -1
  14. package/dist/core/ForgeSQLSelectOperations.d.ts.map +1 -1
  15. package/dist/core/SystemTables.d.ts +167 -0
  16. package/dist/core/SystemTables.d.ts.map +1 -1
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/utils/forgeDriverProxy.d.ts +11 -0
  20. package/dist/utils/forgeDriverProxy.d.ts.map +1 -0
  21. package/dist/utils/sqlHints.d.ts +21 -0
  22. package/dist/utils/sqlHints.d.ts.map +1 -0
  23. package/dist/utils/sqlUtils.d.ts +2 -8
  24. package/dist/utils/sqlUtils.d.ts.map +1 -1
  25. package/dist/webtriggers/applyMigrationsWebTrigger.d.ts.map +1 -1
  26. package/dist/webtriggers/dropMigrationWebTrigger.d.ts +2 -4
  27. package/dist/webtriggers/dropMigrationWebTrigger.d.ts.map +1 -1
  28. package/package.json +4 -12
  29. package/src/core/ForgeSQLAnalyseOperations.ts +461 -0
  30. package/src/core/ForgeSQLCrudOperations.ts +15 -8
  31. package/src/core/ForgeSQLORM.ts +46 -9
  32. package/src/core/ForgeSQLQueryBuilder.ts +129 -32
  33. package/src/core/ForgeSQLSelectOperations.ts +4 -6
  34. package/src/core/SystemTables.ts +175 -0
  35. package/src/index.ts +1 -0
  36. package/src/utils/forgeDriverProxy.ts +27 -0
  37. package/src/utils/sqlHints.ts +63 -0
  38. package/src/utils/sqlUtils.ts +36 -32
  39. package/src/webtriggers/applyMigrationsWebTrigger.ts +32 -16
  40. package/src/webtriggers/dropMigrationWebTrigger.ts +5 -6
  41. package/src/webtriggers/fetchSchemaWebTrigger.ts +2 -10
package/README.md CHANGED
@@ -1,11 +1,23 @@
1
1
  # Forge SQL ORM
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/forge-sql-orm)](https://www.npmjs.com/package/forge-sql-orm)
4
+ [![npm downloads](https://img.shields.io/npm/dm/forge-sql-orm)](https://www.npmjs.com/package/forge-sql-orm)
5
+ [![npm version (CLI)](https://img.shields.io/npm/v/forge-sql-orm-cli?label=cli)](https://www.npmjs.com/package/forge-sql-orm-cli)
6
+ [![npm downloads (CLI)](https://img.shields.io/npm/dm/forge-sql-orm-cli?label=cli%20downloads)](https://www.npmjs.com/package/forge-sql-orm-cli)
7
+
8
+ [![License](https://img.shields.io/github/license/vzakharchenko/forge-sql-orm)](https://github.com/vzakharchenko/forge-sql-orm/blob/master/LICENSE)
9
+
3
10
  [![forge-sql-orm CI](https://github.com/vzakharchenko/forge-sql-orm/actions/workflows/node.js.yml/badge.svg)](https://github.com/vzakharchenko/forge-sql-orm/actions/workflows/node.js.yml)
11
+ [![Coverage Status](https://coveralls.io/repos/github/vzakharchenko/forge-sql-orm/badge.svg?branch=master)](https://coveralls.io/github/vzakharchenko/forge-sql-orm?branch=master)
12
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=vzakharchenko_forge-sql-orm&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=vzakharchenko_forge-sql-orm)
13
+ [![DeepScan grade](https://deepscan.io/api/teams/26652/projects/29272/branches/940614/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=26652&pid=29272&bid=940614)
14
+
4
15
 
5
16
  **Forge-SQL-ORM** is an ORM designed for working with [@forge/sql](https://developer.atlassian.com/platform/forge/storage-reference/sql-tutorial/) in **Atlassian Forge**. It is built on top of [Drizzle ORM](https://orm.drizzle.team) and provides advanced capabilities for working with relational databases inside Forge.
6
17
 
7
18
  ## Key Features
8
19
  - ✅ **Custom Drizzle Driver** for direct integration with @forge/sql
20
+ - ✅ **Type-Safe Query Building**: Write SQL queries with full TypeScript support
9
21
  - ✅ **Supports complex SQL queries** with joins and filtering using Drizzle ORM
10
22
  - ✅ **Schema migration support**, allowing automatic schema evolution
11
23
  - ✅ **Automatic entity generation** from MySQL/tidb databases
@@ -14,7 +26,7 @@
14
26
  - ✅ **Schema Fetching** Development-only web trigger to retrieve current database schema and generate SQL statements for schema recreation
15
27
  - ✅ **Ready-to-use Migration Triggers** Built-in web triggers for applying migrations, dropping tables (development-only), and fetching schema (development-only) with proper error handling and security controls
16
28
  - ✅ **Optimistic Locking** Ensures data consistency by preventing conflicts when multiple users update the same record
17
- - ✅ **Type Safety** Full TypeScript support with proper type inference
29
+ - ✅ **Query Plan Analysis**: Detailed execution plan analysis and optimization insights (Performance analysis and Troubleshooting only)
18
30
 
19
31
  ## Usage Approaches
20
32
 
@@ -587,15 +599,14 @@ This trigger allows you to completely reset your database schema. It's useful fo
587
599
  - Testing scenarios requiring a clean database
588
600
  - Resetting the database before applying new migrations
589
601
 
590
- **Important**: The trigger will only drop tables that are defined in your models. Any tables that exist in the database but are not defined in your models will remain untouched.
602
+ **Important**: The trigger will drop all tables including migration.
591
603
 
592
604
  ```typescript
593
605
  // Example usage in your Forge app
594
606
  import { dropSchemaMigrations } from "forge-sql-orm";
595
- import * as schema from "./entities/schema";
596
607
 
597
608
  export const dropMigrations = () => {
598
- return dropSchemaMigrations(Object.values(schema));
609
+ return dropSchemaMigrations();
599
610
  };
600
611
  ```
601
612
 
@@ -671,6 +682,86 @@ SET foreign_key_checks = 1;
671
682
  - Use these triggers as part of your deployment pipeline
672
683
  - Monitor the execution logs in the Forge Developer Console
673
684
 
685
+ ## Query Analysis and Performance Optimization
686
+
687
+ ⚠️ **IMPORTANT NOTE**: The query analysis features described below are experimental and should be used only for troubleshooting purposes. These features rely on TiDB's `information_schema` and `performance_schema` which may change in future updates. As of April 2025, these features are available but their future availability is not guaranteed.
688
+
689
+ ### About Atlassian's Built-in Analysis Tools
690
+
691
+ Atlassian already provides comprehensive query analysis tools in the development console, including:
692
+ - Basic query performance metrics
693
+ - Slow query tracking (queries over 500ms)
694
+ - Basic execution statistics
695
+ - Query history and patterns
696
+
697
+ Our analysis tools are designed to complement these built-in features by providing additional insights directly from TiDB's system schemas. However, they should be used with caution and only for troubleshooting purposes.
698
+
699
+ ### Usage Guidelines
700
+
701
+ 1. **Development and Troubleshooting Only**
702
+ - These tools should not be used in production code
703
+ - Intended only for development and debugging
704
+ - Use for identifying and fixing performance issues
705
+
706
+ 2. **Schema Stability**
707
+ - Features rely on TiDB's `information_schema` and `performance_schema`
708
+ - Schema structure may change in future TiDB updates
709
+ - No guarantee of long-term availability
710
+
711
+ 3. **Current Availability (April 2025)**
712
+ - `information_schema` based analysis is currently functional
713
+ - Query plan analysis is available
714
+ - Performance metrics collection is working
715
+
716
+ ### Available Analysis Tools
717
+
718
+ ```typescript
719
+ import ForgeSQL from "forge-sql-orm";
720
+
721
+ const forgeSQL = new ForgeSQL();
722
+ const analyzeForgeSql = forgeSQL.analyze();
723
+ ```
724
+
725
+ #### Query Plan Analysis
726
+
727
+ ⚠️ **For Troubleshooting Only**: This feature should only be used during development and debugging sessions.
728
+
729
+ ```typescript
730
+ // Example usage for troubleshooting a specific query
731
+ const forgeSQL = new ForgeSQL();
732
+ const analyzeForgeSql = forgeSQL.analyze();
733
+
734
+ // Analyze a Drizzle query
735
+ const plan = await analyzeForgeSql.explain(
736
+ forgeSQL.select({
737
+ table1: testEntityJoin1,
738
+ table2: { name: testEntityJoin2.name, email: testEntityJoin2.email },
739
+ count: rawSql<number>`COUNT(*)`,
740
+ table3: {
741
+ table12: testEntityJoin1.name,
742
+ table22: testEntityJoin2.email,
743
+ table32: testEntity.id
744
+ },
745
+ })
746
+ .from(testEntityJoin1)
747
+ .innerJoin(testEntityJoin2, eq(testEntityJoin1.id, testEntityJoin2.id))
748
+ );
749
+
750
+ // Analyze a raw SQL query
751
+ const rawPlan = await analyzeForgeSql.explainRaw(
752
+ "SELECT * FROM users WHERE id = ?",
753
+ [1]
754
+ );
755
+ ```
756
+
757
+ This analysis helps you understand:
758
+ - How the database executes your query
759
+ - Which indexes are being used
760
+ - Estimated vs actual row counts
761
+ - Resource usage at each step
762
+ - Potential performance bottlenecks
763
+
764
+
674
765
  ## License
675
766
  This project is licensed under the **MIT License**.
676
767
  Feel free to use it for commercial and personal projects.