metal-orm 1.0.7 → 1.0.9

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 (153) hide show
  1. package/README.md +133 -121
  2. package/dist/decorators/index.cjs +2564 -0
  3. package/dist/decorators/index.cjs.map +1 -0
  4. package/dist/decorators/index.d.cts +53 -0
  5. package/dist/decorators/index.d.ts +53 -0
  6. package/dist/decorators/index.js +2530 -0
  7. package/dist/decorators/index.js.map +1 -0
  8. package/dist/index.cjs +4227 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.cts +701 -0
  11. package/dist/index.d.ts +701 -0
  12. package/dist/index.js +4131 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/select-654m4qy8.d.cts +1522 -0
  15. package/dist/select-654m4qy8.d.ts +1522 -0
  16. package/package.json +27 -20
  17. package/src/codegen/typescript.ts +405 -393
  18. package/src/core/ast/aggregate-functions.ts +30 -0
  19. package/src/core/ast/builders.ts +43 -0
  20. package/src/core/ast/expression-builders.ts +310 -0
  21. package/src/core/ast/expression-nodes.ts +211 -0
  22. package/src/core/ast/expression-visitor.ts +99 -0
  23. package/src/core/ast/expression.ts +5 -0
  24. package/src/{utils → core/ast}/join-node.ts +20 -20
  25. package/src/{ast → core/ast}/join.ts +18 -18
  26. package/src/{ast → core/ast}/query.ts +113 -113
  27. package/src/core/ast/window-functions.ts +140 -0
  28. package/src/{dialect → core/dialect}/abstract.ts +94 -94
  29. package/src/{dialect → core/dialect}/mssql/index.ts +31 -31
  30. package/src/{dialect → core/dialect}/mysql/index.ts +31 -31
  31. package/src/{dialect → core/dialect}/postgres/index.ts +45 -45
  32. package/src/{dialect → core/dialect}/sqlite/index.ts +45 -45
  33. package/src/{constants → core/sql}/sql-operator-config.ts +39 -39
  34. package/src/decorators/bootstrap.ts +126 -0
  35. package/src/decorators/column.ts +78 -0
  36. package/src/decorators/entity.ts +36 -0
  37. package/src/decorators/index.ts +4 -0
  38. package/src/decorators/relations.ts +107 -0
  39. package/src/global.d.ts +1 -0
  40. package/src/index.ts +22 -22
  41. package/src/orm/db-executor.ts +11 -0
  42. package/src/orm/domain-event-bus.ts +52 -0
  43. package/src/{runtime → orm}/entity-meta.ts +52 -52
  44. package/src/orm/entity-metadata.ts +140 -0
  45. package/src/{runtime → orm}/entity.ts +252 -252
  46. package/src/{runtime → orm}/execute.ts +36 -36
  47. package/src/{runtime → orm}/hydration.ts +103 -103
  48. package/src/orm/identity-map.ts +37 -0
  49. package/src/{runtime → orm}/lazy-batch.ts +205 -205
  50. package/src/orm/orm-context.ts +154 -0
  51. package/src/orm/relation-change-processor.ts +140 -0
  52. package/src/{runtime → orm}/relations/belongs-to.ts +92 -92
  53. package/src/{runtime → orm}/relations/has-many.ts +111 -111
  54. package/src/{runtime → orm}/relations/many-to-many.ts +149 -149
  55. package/src/orm/runtime-types.ts +39 -0
  56. package/src/orm/transaction-runner.ts +17 -0
  57. package/src/orm/unit-of-work.ts +232 -0
  58. package/src/{builder/operations → query-builder}/column-selector.ts +78 -78
  59. package/src/{builder → query-builder}/delete-query-state.ts +38 -42
  60. package/src/{builder → query-builder}/delete.ts +46 -57
  61. package/src/{builder → query-builder}/hydration-manager.ts +87 -87
  62. package/src/{builder → query-builder}/hydration-planner.ts +182 -182
  63. package/src/{builder → query-builder}/insert-query-state.ts +51 -62
  64. package/src/{builder → query-builder}/insert.ts +48 -59
  65. package/src/{builder → query-builder}/query-ast-service.ts +208 -226
  66. package/src/{utils → query-builder}/raw-column-parser.ts +32 -32
  67. package/src/{builder → query-builder}/relation-conditions.ts +112 -112
  68. package/src/{builder/operations → query-builder}/relation-manager.ts +82 -82
  69. package/src/{builder → query-builder}/relation-projection-helper.ts +101 -101
  70. package/src/{builder → query-builder}/relation-service.ts +284 -284
  71. package/src/{builder → query-builder}/relation-types.ts +21 -21
  72. package/src/{builder → query-builder}/relation-utils.ts +12 -12
  73. package/src/{builder → query-builder}/select-query-builder-deps.ts +112 -94
  74. package/src/{builder → query-builder}/select-query-state.ts +179 -179
  75. package/src/{builder → query-builder}/select.ts +78 -69
  76. package/src/{builder → query-builder}/update-query-state.ts +55 -59
  77. package/src/{builder → query-builder}/update.ts +50 -61
  78. package/src/schema/column.ts +25 -25
  79. package/src/schema/relation.ts +116 -116
  80. package/src/schema/table.ts +34 -34
  81. package/src/schema/types.ts +76 -76
  82. package/.github/workflows/publish-metal-orm.yml +0 -38
  83. package/ROADMAP.md +0 -125
  84. package/docs/CHANGES.md +0 -104
  85. package/docs/advanced-features.md +0 -176
  86. package/docs/api-reference.md +0 -31
  87. package/docs/dml-operations.md +0 -156
  88. package/docs/getting-started.md +0 -171
  89. package/docs/hydration.md +0 -115
  90. package/docs/index.md +0 -36
  91. package/docs/multi-dialect-support.md +0 -59
  92. package/docs/query-builder.md +0 -135
  93. package/docs/runtime.md +0 -105
  94. package/docs/schema-definition.md +0 -112
  95. package/metadata.json +0 -5
  96. package/playground/api/playground-api.ts +0 -94
  97. package/playground/index.html +0 -15
  98. package/playground/src/App.css +0 -1
  99. package/playground/src/App.tsx +0 -114
  100. package/playground/src/components/CodeDisplay.tsx +0 -43
  101. package/playground/src/components/QueryExecutor.tsx +0 -189
  102. package/playground/src/components/ResultsTable.tsx +0 -67
  103. package/playground/src/components/ResultsTabs.tsx +0 -105
  104. package/playground/src/components/ScenarioList.tsx +0 -56
  105. package/playground/src/components/logo.svg +0 -45
  106. package/playground/src/data/scenarios.ts +0 -2
  107. package/playground/src/main.tsx +0 -9
  108. package/playground/src/services/PlaygroundApiService.ts +0 -60
  109. package/postcss.config.cjs +0 -5
  110. package/sql_sql-ansi-cheatsheet-2025.md +0 -264
  111. package/src/ast/expression.ts +0 -658
  112. package/src/builder/operations/cte-manager.ts +0 -34
  113. package/src/builder/operations/filter-manager.ts +0 -68
  114. package/src/builder/operations/join-manager.ts +0 -36
  115. package/src/builder/operations/pagination-manager.ts +0 -36
  116. package/src/playground/features/playground/api/types.ts +0 -16
  117. package/src/playground/features/playground/clients/MockClient.ts +0 -17
  118. package/src/playground/features/playground/clients/SqliteClient.ts +0 -57
  119. package/src/playground/features/playground/common/IDatabaseClient.ts +0 -10
  120. package/src/playground/features/playground/data/scenarios/aggregation.ts +0 -36
  121. package/src/playground/features/playground/data/scenarios/basics.ts +0 -25
  122. package/src/playground/features/playground/data/scenarios/edge_cases.ts +0 -57
  123. package/src/playground/features/playground/data/scenarios/filtering.ts +0 -94
  124. package/src/playground/features/playground/data/scenarios/hydration.ts +0 -27
  125. package/src/playground/features/playground/data/scenarios/index.ts +0 -29
  126. package/src/playground/features/playground/data/scenarios/ordering.ts +0 -25
  127. package/src/playground/features/playground/data/scenarios/pagination.ts +0 -16
  128. package/src/playground/features/playground/data/scenarios/relationships.ts +0 -75
  129. package/src/playground/features/playground/data/scenarios/types.ts +0 -70
  130. package/src/playground/features/playground/data/schema.ts +0 -91
  131. package/src/playground/features/playground/data/seed.ts +0 -104
  132. package/src/playground/features/playground/services/QueryExecutionService.ts +0 -121
  133. package/src/runtime/orm-context.ts +0 -539
  134. package/tests/belongs-to-many.test.ts +0 -57
  135. package/tests/between.test.ts +0 -43
  136. package/tests/case-expression.test.ts +0 -58
  137. package/tests/complex-exists.test.ts +0 -230
  138. package/tests/cte.test.ts +0 -118
  139. package/tests/dml.test.ts +0 -206
  140. package/tests/exists.test.ts +0 -127
  141. package/tests/like.test.ts +0 -33
  142. package/tests/orm-runtime.test.ts +0 -254
  143. package/tests/postgres.test.ts +0 -30
  144. package/tests/right-join.test.ts +0 -89
  145. package/tests/subquery-having.test.ts +0 -193
  146. package/tests/window-function.test.ts +0 -151
  147. package/tsconfig.json +0 -30
  148. package/tsup.config.ts +0 -10
  149. package/vite.config.ts +0 -22
  150. package/vitest.config.ts +0 -14
  151. /package/src/{constants → core/sql}/sql.ts +0 -0
  152. /package/src/{runtime → orm}/als.ts +0 -0
  153. /package/src/{utils → query-builder}/relation-alias.ts +0 -0
@@ -1,60 +0,0 @@
1
- import type { ApiStatusResponse, QueryExecutionResult } from '@orm/playground/features/playground/api/types';
2
-
3
- const DEFAULT_API_BASE = '/api/playground';
4
-
5
- export class PlaygroundApiService {
6
- constructor(private basePath: string = DEFAULT_API_BASE) {}
7
-
8
- async getStatus(): Promise<ApiStatusResponse> {
9
- try {
10
- const response = await fetch(`${this.basePath}/status`);
11
- if (!response.ok) {
12
- const message = await response.text();
13
- return {
14
- ready: false,
15
- error: message || 'Unable to reach the playground API',
16
- };
17
- }
18
-
19
- return (await response.json()) as ApiStatusResponse;
20
- } catch (error) {
21
- return {
22
- ready: false,
23
- error: error instanceof Error ? error.message : 'Unknown network error',
24
- };
25
- }
26
- }
27
-
28
- async executeScenario(scenarioId: string): Promise<QueryExecutionResult> {
29
- try {
30
- const response = await fetch(`${this.basePath}/execute`, {
31
- method: 'POST',
32
- headers: { 'Content-Type': 'application/json' },
33
- body: JSON.stringify({ scenarioId }),
34
- });
35
-
36
- if (!response.ok) {
37
- const message = await response.text();
38
- return {
39
- sql: '',
40
- params: [],
41
- typescriptCode: '',
42
- results: [],
43
- error: message || 'Unable to execute scenario',
44
- executionTime: 0,
45
- };
46
- }
47
-
48
- return (await response.json()) as QueryExecutionResult;
49
- } catch (error) {
50
- return {
51
- sql: '',
52
- params: [],
53
- typescriptCode: '',
54
- results: [],
55
- error: error instanceof Error ? error.message : 'Unknown network error',
56
- executionTime: 0,
57
- };
58
- }
59
- }
60
- }
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- plugins: {
3
- 'postcss-preset-mantine': {},
4
- },
5
- };
@@ -1,264 +0,0 @@
1
-
2
- # SQL Feature Compatibility Cheat Sheet (ANSI vs Major RDBMS vs Metal-ORM, 2025)
3
-
4
- This document summarizes a broad set of SQL features and indicates:
5
-
6
- - **ANSI?**
7
- - ✔ = defined in some version of the SQL standard (SQL‑92, SQL:1999, SQL:2003, SQL:2011, SQL:2016, SQL:2023, etc.)
8
- - (P) = partially standardized / standardized but implemented with significant variation
9
- - ✖ = purely dialect-specific (non‑ANSI)
10
- - **Database support**
11
- - **PG** = PostgreSQL 15+/18+
12
- - **MY** = MySQL 8.0.31+/8.4+
13
- - **MS** = Microsoft SQL Server 2022 / 2025
14
- - **OR** = Oracle Database 19c / 23ai
15
- - **SQ** = SQLite 3.39+
16
- - **MO** = Metal-ORM (current implementation)
17
-
18
- Support legend in the tables:
19
-
20
- - ✔ = feature is supported and commonly used
21
- - ~ = partially supported, different semantics, or requires workarounds
22
- - ✖ = not supported
23
-
24
- ---
25
-
26
- ## 1. DQL / DML Basics
27
-
28
- | Feature / Syntax | Category | ANSI | PG | MY | MS | OR | SQ | MO | Notes |
29
- |--------------------------------------------|----------------|:----:|:---:|:---:|:---:|:---:|:---:|:---:|----------------------------------------------------------------------------|
30
- | `SELECT` | DQL | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Basic query |
31
- | `SELECT DISTINCT` | DQL | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Removes duplicates |
32
- | `FROM` | DQL | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Source tables/views |
33
- | `WHERE` | Filter | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Row-level filtering |
34
- | `GROUP BY` | Aggregation | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Grouping for aggregates |
35
- | `HAVING` | Aggregation | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Filter after grouping |
36
- | `ORDER BY` | Sorting | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Result ordering |
37
- | `LIMIT n` | Pagination | ✖ | ✔ | ✔ | ✖ | ~ | ✔ | ✔ | Non‑standard; standard uses `FETCH FIRST` |
38
- | `OFFSET n` | Pagination | (P) | ✔ | ✔ | (P) | (P) | ✔ | ✔ | Common in PG/MY/SQ; MS/OR use `FETCH`/`OFFSET` |
39
- | `FETCH FIRST n ROWS ONLY` | Pagination | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | ~ | Standard way to limit number of rows |
40
- | `INSERT INTO ... VALUES (...)` | DML | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | Literal insert |
41
- | `INSERT INTO ... SELECT ...` | DML | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | Insert from query |
42
- | `UPDATE ... SET ...` | DML | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | Update rows |
43
- | `DELETE FROM ...` | DML | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | Delete rows |
44
- | `MERGE INTO ... USING ...` | Advanced DML | ✔ | ✔ | ✖ | ✔ | ✔ | ✖ | ✖ | Standard UPSERT; MY/SQ rely on non‑standard alternatives |
45
- | `RETURNING` (after DML) | Advanced DML | (P) | ✔ | ✖ | ~ | ~ | ✖ | ✖ | Newer standard / partial; heavily used in PostgreSQL |
46
- | `CALL procedure(...)` | Procedures | (P) | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | Standard in SQL/PSM, but syntax details vary |
47
-
48
- ---
49
-
50
- ## 2. Predicates, Operators, and Expressions
51
-
52
- | Feature / Syntax | Category | ANSI | PG | MY | MS | OR | SQ | MO | Notes |
53
- |----------------------------------|------------------|:----:|:---:|:---:|:---:|:---:|:---:|:---:|-------------------------------------------------------------|
54
- | `=`, `<>`, `<`, `>`, `<=`, `>=` | Comparison | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Standard comparison operators |
55
- | `AND`, `OR`, `NOT` | Boolean | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Boolean operators |
56
- | `BETWEEN a AND b` | Predicate | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Inclusive range |
57
- | `IN (values/subquery)` | Predicate | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Membership in a list |
58
- | `LIKE 'pattern'` | Predicate | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Pattern matching with `%` and `_` |
59
- | `LIKE ... ESCAPE ''` | Predicate | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Explicit escape character (Metal-ORM exposes `escape` in `like`/`notLike`) |
60
- | `IS NULL` / `IS NOT NULL` | Predicate | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | NULL tests |
61
- | `EXISTS (subquery)` | Predicate | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Tests for row existence |
62
- | `CASE WHEN ... THEN ... END` | Expression | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Standard conditional expression |
63
- | `COALESCE(a,b,...)` | Scalar function | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | First non‑NULL |
64
- | `NULLIF(a,b)` | Scalar function | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | Returns NULL if `a = b` |
65
- | `IS DISTINCT FROM` | NULL‑safe compare| (P) | ✔ | ~ | ~ | ~ | ✔ | ✖ | Standardized later; implementations differ |
66
- | `ILIKE` | Text | ✖ | ✔ | ✖ | ✖ | ✖ | ✖ | ✖ | PostgreSQL case‑insensitive LIKE |
67
- | Regex predicates (`~`, `REGEXP`)| Text / Regex | ✖ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | Regex support is non‑standard everywhere |
68
-
69
- ---
70
-
71
- ## 3. Aggregations and GROUP BY
72
-
73
- | Feature / Syntax | Category | ANSI | PG | MY | MS | OR | SQ | MO | Notes |
74
- |-------------------------------------------|---------------|:----:|:---:|:---:|:---:|:---:|:---:|:---:|------------------------------------------------------------------------|
75
- | `COUNT(*)` | Aggregate | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Counts rows |
76
- | `SUM(expr)` | Aggregate | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Sums values |
77
- | `AVG(expr)` | Aggregate | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Average |
78
- | `MIN(expr)`, `MAX(expr)` | Aggregate | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Minimum / maximum |
79
- | `GROUP BY col,...` | Grouping | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Groups rows for aggregation |
80
- | `HAVING cond` | Group filter | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Filter after `GROUP BY` |
81
- | `GROUPING SETS (...)` | Grouping | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | Explicit grouping sets |
82
- | `ROLLUP (...)` | Grouping | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | Hierarchical subtotals |
83
- | `CUBE (...)` | Grouping | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | All dimension combinations |
84
- | `DISTINCT` in aggregates (`COUNT(DISTINCT)`)| Aggregate | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | Distinct values inside aggregate |
85
-
86
- ---
87
-
88
- ## 4. JOINs and Set Operations
89
-
90
- | Feature / Syntax | Category | ANSI | PG | MY | MS | OR | SQ | MO | Notes |
91
- |---------------------------------------|-------------------|:----:|:---:|:---:|:---:|:---:|:---:|:---:|-------------------------------------------------------------------------------------|
92
- | `CROSS JOIN` | Join | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Cartesian product |
93
- | `[INNER] JOIN ... ON ...` | Join | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Inner join |
94
- | `LEFT [OUTER] JOIN` | Join | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Left outer join |
95
- | `RIGHT [OUTER] JOIN` | Join | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Supported in recent SQLite; older versions lack it |
96
- | `FULL [OUTER] JOIN` | Join | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | Supported in recent SQLite; older versions use workarounds |
97
- | `NATURAL JOIN` | Join | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | Joins on columns with same name |
98
- | `JOIN ... USING (col,...)` | Join | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | Shorthand for join on columns with same name |
99
- | `LATERAL` / `CROSS APPLY` | Advanced join | (P) | ✔ | ✖ | ~ | ~ | ✖ | ✖ | Standard has `LATERAL`; SQL Server uses `CROSS/OUTER APPLY` (non‑standard) |
100
- | `UNION` | Set operation | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | Union with duplicate elimination |
101
- | `UNION ALL` | Set operation | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | Union without duplicate elimination |
102
- | `INTERSECT` | Set operation | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | MySQL 8.0.31+ supports `INTERSECT` |
103
- | `EXCEPT` | Set operation | ✔ | ✔ | ✔ | ✔ | ✖ | ✔ | ✖ | Oracle uses `MINUS` instead of `EXCEPT` |
104
- | `MINUS` | Set operation | ✖ | ✖ | ✖ | ✖ | ✔ | ✖ | ✖ | Oracle‑specific equivalent of `EXCEPT` |
105
-
106
- ---
107
-
108
- ## 5. DDL: Tables, Indexes, Schemas
109
-
110
- | Feature / Syntax | Category | ANSI | PG | MY | MS | OR | SQ | MO | Notes |
111
- |--------------------------------------|-----------|:----:|:---:|:---:|:---:|:---:|:---:|:---:|-------------------------------------------------------------------------|
112
- | `CREATE TABLE` | DDL | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Table creation |
113
- | `ALTER TABLE ADD COLUMN` | DDL | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Add column |
114
- | `ALTER TABLE ALTER/MODIFY COLUMN` | DDL | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Syntax differs by database |
115
- | `ALTER TABLE DROP COLUMN` | DDL | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Drop column |
116
- | `DROP TABLE` | DDL | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Drop table |
117
- | `CREATE SCHEMA` | DDL | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✔ | SQLite does not implement separate schemas |
118
- | `DROP SCHEMA` | DDL | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✔ | Same as above |
119
- | `CREATE DATABASE` | DDL | ✖ | ✔ | ✔ | ✔ | ✔ | ✖ | ✔ | Non‑standard; engine‑specific |
120
- | `DROP DATABASE` | DDL | ✖ | ✔ | ✔ | ✔ | ✔ | ✖ | ✔ | Same |
121
- | `CREATE VIEW` | DDL | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Logical view |
122
- | `CREATE MATERIALIZED VIEW` | DDL | (P) | ✔ | ✖ | ~ | ✔ | ✖ | ✖ | PG/OR support materialized views; MS uses indexed views (~) |
123
- | `CREATE INDEX` | DDL | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Index creation |
124
- | `DROP INDEX` | DDL | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Drop index |
125
- | `CREATE SEQUENCE` | DDL | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | Sequence object; SQLite has no sequences |
126
- | `ALTER SEQUENCE`, `NEXT VALUE FOR` | DDL | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | Syntax differs; concept is standardized |
127
-
128
- ---
129
-
130
- ## 6. Constraints and Referential Integrity
131
-
132
- | Feature / Syntax | Category | ANSI | PG | MY | MS | OR | SQ | MO | Notes |
133
- |---------------------------------------------------|--------------------------|:----:|:---:|:---:|:---:|:---:|:---:|:---:|----------------------------------------------------------------------------------|
134
- | `PRIMARY KEY` | Constraint | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Primary key |
135
- | `UNIQUE` | Constraint | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Unique constraint |
136
- | `NOT NULL` | Constraint | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Disallow NULL |
137
- | `CHECK (condition)` | Constraint | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | SQLite enforces `CHECK` fully only in newer versions |
138
- | `FOREIGN KEY (...) REFERENCES t(col,...)` | Referential integrity | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | SQ requires foreign_keys pragma in some setups |
139
- | `ON DELETE CASCADE/SET NULL/SET DEFAULT/RESTRICT` | Referential actions | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | ✔ | SQLite may not implement all actions in older versions |
140
- | `ON UPDATE CASCADE/SET NULL/SET DEFAULT/RESTRICT` | Referential actions | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | ✔ | Same as above |
141
- | `DEFERRABLE` / `INITIALLY DEFERRED` | Advanced constraint | ✔ | ✔ | ✖ | ~ | ✔ | ✖ | ✖ | Controls when constraint is checked (end of transaction vs row‑by‑row) |
142
-
143
- ---
144
-
145
- ## 7. Transactions, Locking, and Security
146
-
147
- | Feature / Syntax | Category | ANSI | PG | MY | MS | OR | SQ | MO | Notes |
148
- |---------------------------------------|----------------|:----:|:---:|:---:|:---:|:---:|:---:|:---:|--------------------------------------------------------------------|
149
- | `BEGIN` / `START TRANSACTION` | Transaction | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Starts transaction |
150
- | `COMMIT` | Transaction | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Commit changes |
151
- | `ROLLBACK` | Transaction | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Roll back changes |
152
- | `SAVEPOINT name` | Transaction | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Intermediate transaction marker |
153
- | `ROLLBACK TO SAVEPOINT` | Transaction | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Roll back to savepoint |
154
- | `SET TRANSACTION ISOLATION LEVEL ...` | Transaction | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | ✔ | SQ does not expose standard isolation level syntax |
155
- | `GRANT ... ON ... TO ...` | Security | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✔ | Privilege management |
156
- | `REVOKE ... FROM ...` | Security | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✔ | Revoke privileges |
157
- | `CREATE ROLE` / `CREATE USER` | Security | (P) | ✔ | ✔ | ✔ | ✔ | ✖ | ✔ | User/role model is standardized conceptually but differs in detail |
158
-
159
- ---
160
-
161
- ## 8. Data Types (Main Groups)
162
-
163
- | Type / Feature | Category | ANSI | PG | MY | MS | OR | SQ | MO | Notes |
164
- |-------------------------------------|--------------|:----:|:---:|:---:|:---:|:---:|:---:|:---:|-----------------------------------------------------------------------|
165
- | `INTEGER` / `SMALLINT` / `BIGINT` | Numeric | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | ✔ | SQ stores values dynamically (affinity model) |
166
- | `DECIMAL(p,s)` / `NUMERIC(p,s)` | Numeric | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | ✔ | Exact precision |
167
- | `REAL` / `DOUBLE PRECISION` / `FLOAT` | Numeric | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | ✔ | Floating‑point |
168
- | `CHAR(n)`, `VARCHAR(n)` | Text | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | ✔ | Basic text types |
169
- | `CLOB`, `BLOB` | LOB | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | ✔ | Large objects; names differ (TEXT, BYTEA, etc.) |
170
- | `DATE` | Date/Time | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | ✔ | Date only |
171
- | `TIME [WITH/WITHOUT TIME ZONE]` | Date/Time | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | ✔ | Time only |
172
- | `TIMESTAMP [WITH/WITHOUT TIME ZONE]`| Date/Time | ✔ | ✔ | ✔ | ✔ | ✔ | ~ | ✔ | Date+time; names and aliases differ |
173
- | `INTERVAL` | Date/Time | ✔ | ✔ | ✖ | ✖ | ✔ | ✖ | ✖ | PG/OR implement rich INTERVAL; MY/MS use functions instead |
174
- | `BOOLEAN` | Boolean | ✔ | ✔ | ~ | ✔ | ✔ | ~ | ✔ | MY maps to `TINYINT(1)`; SQ accepts but does not enforce strongly |
175
- | `ENUM` | Text | ✖ | ✔ | ✔ | ✖ | ✖ | ✖ | ✖ | Extension in PG/MY |
176
- | `JSON` / `JSONB` (native type) | JSON | (P) | ✔ | ✔ | ✔ | ✔ | ~ | ✔ | SQL/JSON is standardized; native type details vary |
177
- | `XML` (native type) | XML | (P) | ✔ | ✖ | ✔ | ✔ | ✖ | ✖ | SQL/XML in standard; strong support in OR/MS/PG |
178
- | `ARRAY` | Collection | ✖ | ✔ | ✖ | ✖ | ~ | ✖ | ✖ | Powerful extension in PostgreSQL |
179
-
180
- ---
181
-
182
- ## 9. CTEs and Window Functions
183
-
184
- | Feature / Syntax | Category | ANSI | PG | MY | MS | OR | SQ | MO | Notes |
185
- |---------------------------------------------------|-------------------|:----:|:---:|:---:|:---:|:---:|:---:|:---:|-----------------------------------------------------------------------|
186
- | `WITH cte AS (SELECT ...)` | Non‑recursive CTE | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Named temporary result set |
187
- | `WITH RECURSIVE cte AS (...)` | Recursive CTE | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Hierarchical / recursive queries |
188
- | `func(...) OVER (PARTITION BY ... ORDER BY ...)` | Window function | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Window functions standardized in SQL:2003+ |
189
- | `ROW_NUMBER() OVER (...)` | Window function | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Sequential numbering |
190
- | `RANK()`, `DENSE_RANK()` OVER (...) | Window function | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Ranking with ties |
191
- | `LAG(expr)`, `LEAD(expr)` OVER (...) | Window function | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Access previous/next row |
192
- | `NTILE(n) OVER (...)` | Window function | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Buckets rows into quantiles |
193
- | `WINDOW w AS (PARTITION BY ... ORDER BY ...)` | Window clause | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Names a window for reuse |
194
-
195
- ---
196
-
197
- ## 10. Programmability, Triggers, and Metadata
198
-
199
- | Feature / Syntax | Category | ANSI | PG | MY | MS | OR | SQ | MO | Notes |
200
- |--------------------------------------------|---------------------|:----:|:---:|:---:|:---:|:---:|:---:|:---:|-------------------------------------------------------------------------------|
201
- | `CREATE PROCEDURE` | Stored procedure | (P) | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | SQL/PSM defines it, but each DB has its own procedural language |
202
- | `CREATE FUNCTION` | Stored function | (P) | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | In PG/OR, can be SQL/PL; in MS/MY, proprietary dialects |
203
- | `CREATE TRIGGER` | Trigger | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | `BEFORE`/`AFTER` on DML operations |
204
- | `INSTEAD OF` trigger | View trigger | (P) | ✔ | ✖ | ✔ | ✔ | ✖ | ✖ | Intercepts operations on views |
205
- | Exception / error handling (`SIGNAL`, etc)| Error handling | (P) | ~ | ✔ | ✔ | ✔ | ✖ | ✖ | SQL/PSM defines it; implementations vary greatly |
206
- | `INFORMATION_SCHEMA.TABLES`, `COLUMNS`,... | Standard metadata | ✔ | ✔ | ✔ | ✔ | ~ | ✖ | ✖ | Standard metadata views; Oracle focuses more on `ALL_*/USER_*/DBA_*` views |
207
- | Native catalogs (`pg_catalog`, `sys`, etc)| Native metadata | ✖ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | Engine‑specific catalog views |
208
-
209
- ---
210
-
211
- ## 11. Common Non‑ANSI Dialect Extensions
212
-
213
- | Feature / Syntax | Dialect | ANSI | PG | MY | MS | OR | SQ | Notes |
214
- |----------------------------------------|------------|:----:|:---:|:---:|:---:|:---:|:---:|-----------------------------------------------------------------|
215
- | `SERIAL` / `BIGSERIAL` | PostgreSQL | ✖ | ✔ | ✖ | ✖ | ✖ | ✖ | Sugar for sequence + default |
216
- | `AUTO_INCREMENT` | MySQL | ✖ | ✖ | ✔ | ✖ | ✖ | ✖ | Built‑in auto increment |
217
- | `IDENTITY(1,1)` | SQL Server | ✖ | ✖ | ✖ | ✔ | ~ | ✖ | Identity columns |
218
- | `NVARCHAR`, `NCHAR` | Unicode | ✖ | ✔ | ✔ | ✔ | ✔ | ✖ | Unicode‑aware character types |
219
- | `NVL(expr, alt)` | Oracle/MS | ✖ | ✖ | ✖ | ✔ | ✔ | ✖ | COALESCE‑like (2 arguments) |
220
- | `DECODE(expr, v1,r1, ..., default)` | Oracle | ✖ | ✖ | ✖ | ✖ | ✔ | ✖ | Oracle conditional expression (switch‑like) |
221
- | `TOP (n) [PERCENT]` | SQL Server | ✖ | ✖ | ✖ | ✔ | ✖ | ✖ | Non‑standard row limit |
222
- | `INSERT ... ON CONFLICT DO ...` | PostgreSQL | ✖ | ✔ | ✖ | ✖ | ✖ | ✖ | PostgreSQL UPSERT |
223
- | `INSERT ... ON DUPLICATE KEY UPDATE` | MySQL | ✖ | ✖ | ✔ | ✖ | ✖ | ✖ | MySQL UPSERT |
224
- | `REPLACE INTO` | MySQL/SQ | ✖ | ✖ | ✔ | ✖ | ✖ | ✔ | DELETE+INSERT semantics |
225
- | JSON operators (`->`, `->>`, `#>`...) | PostgreSQL | ✖ | ✔ | ✖ | ✖ | ✖ | ✖ | Rich JSON manipulation |
226
- | `CONNECT BY PRIOR` | Oracle | ✖ | ✖ | ✖ | ✖ | ✔ | ✖ | Legacy hierarchical query syntax |
227
- | `PRAGMA ...` | SQLite | ✖ | ✖ | ✖ | ✖ | ✖ | ✔ | Engine configuration knobs (foreign_keys, journal_mode, etc.) |
228
-
229
- ---
230
-
231
- This cheat sheet focuses on SQL language features and their support across major relational databases and Metal-ORM in 2025. For exact behavior and edge cases, always consult the official documentation of each RDBMS.
232
-
233
- ---
234
-
235
- ## Metal-ORM Support Summary
236
-
237
- **Fully Supported Features (✔):**
238
- - Basic DQL/DML: SELECT, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, OFFSET
239
- - Joins: INNER, LEFT, RIGHT joins with smart relation handling
240
- - CTEs: WITH and WITH RECURSIVE support
241
- - Window Functions: ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD, NTILE, etc.
242
- - Subqueries: EXISTS, NOT EXISTS, scalar subqueries
243
- - Expressions: CASE WHEN, BETWEEN, IN, IS NULL, etc.
244
- - Aggregations: COUNT, SUM, AVG, MIN, MAX, etc.
245
- - Basic DDL operations: CREATE/DROP TABLE, INDEX, VIEW, SCHEMA, DATABASE
246
- - Constraints: PRIMARY KEY, UNIQUE, NOT NULL, CHECK, FOREIGN KEY
247
- - Transactions: BEGIN, COMMIT, ROLLBACK, SAVEPOINT
248
-
249
- **Partially Supported Features (~):** - LIKE ESCAPE, COALESCE, NULLIF, DISTINCT in aggregates
250
- - FETCH FIRST n ROWS ONLY (partial support)
251
- - SET TRANSACTION ISOLATION LEVEL (partial support)
252
-
253
- **Not Supported Features (✖):**
254
- - Advanced DML: MERGE, RETURNING, CALL procedure
255
- - Advanced joins: LATERAL, CROSS APPLY, NATURAL JOIN, JOIN USING
256
- - Set operations: UNION, UNION ALL, INTERSECT, EXCEPT, MINUS
257
- - Advanced constraints: DEFERRABLE, INITIALLY DEFERRED
258
- - Advanced DDL: CREATE MATERIALIZED VIEW, CREATE SEQUENCE, ALTER SEQUENCE
259
- - Advanced data types: ENUM, XML, ARRAY
260
- - Dialect-specific features: SERIAL, AUTO_INCREMENT, IDENTITY, NVARCHAR, NVL, DECODE, TOP, ON CONFLICT, ON DUPLICATE KEY, REPLACE INTO, JSON operators, CONNECT BY PRIOR, PRAGMA
261
- - Programmability: CREATE PROCEDURE, CREATE FUNCTION, CREATE TRIGGER, INSTEAD OF trigger, Exception handling
262
- - Metadata: INFORMATION_SCHEMA, Native catalogs
263
-
264
- For exact behavior and edge cases, always consult the official documentation of each RDBMS.