@riao/dbal 3.8.0 → 3.9.0

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 (269) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/LICENSE.md +20 -20
  3. package/README.md +148 -148
  4. package/builder/builder.d.ts +7 -7
  5. package/builder/builder.js +19 -19
  6. package/builder/index.d.ts +2 -2
  7. package/builder/index.js +7 -7
  8. package/builder/sql-builder.d.ts +54 -53
  9. package/builder/sql-builder.js +161 -157
  10. package/builder/sql-builder.js.map +1 -1
  11. package/builder/statement-builder.d.ts +12 -12
  12. package/builder/statement-builder.js +32 -32
  13. package/column/column-options.d.ts +156 -156
  14. package/column/column-options.js +2 -2
  15. package/column/column-type.d.ts +18 -18
  16. package/column/column-type.js +27 -27
  17. package/column/column-values.d.ts +34 -34
  18. package/column/column-values.js +2 -2
  19. package/column/create-column-template.d.ts +11 -0
  20. package/column/create-column-template.js +57 -0
  21. package/column/create-column-template.js.map +1 -0
  22. package/column/index.d.ts +4 -3
  23. package/column/index.js +20 -19
  24. package/column/index.js.map +1 -1
  25. package/column-pack/date-time/create-timestamp-column.d.ts +2 -2
  26. package/column-pack/date-time/create-timestamp-column.js +10 -10
  27. package/column-pack/date-time/index.d.ts +2 -2
  28. package/column-pack/date-time/index.js +7 -7
  29. package/column-pack/date-time/update-timestamp-column.d.ts +2 -2
  30. package/column-pack/date-time/update-timestamp-column.js +14 -14
  31. package/column-pack/index.d.ts +6 -6
  32. package/column-pack/index.js +22 -22
  33. package/column-pack/keys/big-int-key-column.d.ts +2 -2
  34. package/column-pack/keys/big-int-key-column.js +10 -10
  35. package/column-pack/keys/index.d.ts +3 -3
  36. package/column-pack/keys/index.js +9 -9
  37. package/column-pack/keys/int-key-column.d.ts +2 -2
  38. package/column-pack/keys/int-key-column.js +10 -10
  39. package/column-pack/keys/uuid-key-column.d.ts +2 -2
  40. package/column-pack/keys/uuid-key-column.js +11 -11
  41. package/column-pack/person/date-of-birth-column.d.ts +2 -2
  42. package/column-pack/person/date-of-birth-column.js +8 -8
  43. package/column-pack/person/first-name-column.d.ts +2 -2
  44. package/column-pack/person/first-name-column.js +9 -9
  45. package/column-pack/person/index.d.ts +3 -3
  46. package/column-pack/person/index.js +9 -9
  47. package/column-pack/person/last-name-column.d.ts +2 -2
  48. package/column-pack/person/last-name-column.js +9 -9
  49. package/column-pack/resource/content-column.d.ts +2 -2
  50. package/column-pack/resource/content-column.js +9 -9
  51. package/column-pack/resource/description-column.d.ts +2 -2
  52. package/column-pack/resource/description-column.js +9 -9
  53. package/column-pack/resource/index.d.ts +6 -6
  54. package/column-pack/resource/index.js +15 -15
  55. package/column-pack/resource/is-active-column.d.ts +2 -2
  56. package/column-pack/resource/is-active-column.js +9 -9
  57. package/column-pack/resource/name-column.d.ts +2 -2
  58. package/column-pack/resource/name-column.js +10 -10
  59. package/column-pack/resource/path-column.d.ts +2 -2
  60. package/column-pack/resource/path-column.js +11 -11
  61. package/column-pack/resource/title-column.d.ts +2 -2
  62. package/column-pack/resource/title-column.js +10 -10
  63. package/column-pack/system/filename-column.d.ts +2 -2
  64. package/column-pack/system/filename-column.js +9 -9
  65. package/column-pack/system/filepath-column.d.ts +2 -2
  66. package/column-pack/system/filepath-column.js +9 -9
  67. package/column-pack/system/index.d.ts +4 -4
  68. package/column-pack/system/index.js +11 -11
  69. package/column-pack/system/ip-address-column.d.ts +2 -2
  70. package/column-pack/system/ip-address-column.js +9 -9
  71. package/column-pack/system/url-column.d.ts +3 -3
  72. package/column-pack/system/url-column.js +13 -13
  73. package/column-pack/user/email-column.d.ts +2 -2
  74. package/column-pack/user/email-column.js +11 -11
  75. package/column-pack/user/index.d.ts +4 -4
  76. package/column-pack/user/index.js +11 -11
  77. package/column-pack/user/password-column.d.ts +2 -2
  78. package/column-pack/user/password-column.js +10 -10
  79. package/column-pack/user/temp-email-column.d.ts +2 -2
  80. package/column-pack/user/temp-email-column.js +5 -5
  81. package/column-pack/user/username-column.d.ts +2 -2
  82. package/column-pack/user/username-column.js +11 -11
  83. package/comparison/comparison-aliases.d.ts +10 -10
  84. package/comparison/comparison-aliases.js +40 -40
  85. package/comparison/comparison-token.d.ts +17 -17
  86. package/comparison/comparison-token.js +15 -15
  87. package/comparison/comparison.d.ts +13 -13
  88. package/comparison/comparison.js +71 -71
  89. package/comparison/index.d.ts +4 -4
  90. package/comparison/index.js +24 -24
  91. package/comparison/is-comparison-token.d.ts +2 -2
  92. package/comparison/is-comparison-token.js +8 -8
  93. package/config/configure-db.d.ts +14 -14
  94. package/config/configure-db.js +18 -18
  95. package/config/database-env.d.ts +16 -16
  96. package/config/database-env.js +14 -14
  97. package/config/index.d.ts +2 -2
  98. package/config/index.js +7 -7
  99. package/database/connection-options.d.ts +7 -7
  100. package/database/connection-options.js +2 -2
  101. package/database/database.d.ts +204 -204
  102. package/database/database.js +330 -330
  103. package/database/driver-query.d.ts +10 -10
  104. package/database/driver-query.js +2 -2
  105. package/database/driver.d.ts +12 -12
  106. package/database/driver.js +47 -47
  107. package/database/get-database-path.d.ts +6 -6
  108. package/database/get-database-path.js +12 -12
  109. package/database/index.d.ts +7 -7
  110. package/database/index.js +26 -26
  111. package/database/load-database.d.ts +9 -9
  112. package/database/load-database.js +36 -36
  113. package/database/transaction.d.ts +8 -8
  114. package/database/transaction.js +2 -2
  115. package/ddl/alter-table.d.ts +26 -26
  116. package/ddl/alter-table.js +2 -2
  117. package/ddl/create-database.d.ts +3 -3
  118. package/ddl/create-database.js +2 -2
  119. package/ddl/create-index.d.ts +5 -5
  120. package/ddl/create-index.js +2 -2
  121. package/ddl/create-table.d.ts +8 -8
  122. package/ddl/create-table.js +2 -2
  123. package/ddl/create-user.d.ts +4 -4
  124. package/ddl/create-user.js +2 -2
  125. package/ddl/ddl-builder.d.ts +96 -96
  126. package/ddl/ddl-builder.js +565 -565
  127. package/ddl/ddl-repository.d.ts +135 -135
  128. package/ddl/ddl-repository.js +228 -228
  129. package/ddl/drop-database.d.ts +4 -4
  130. package/ddl/drop-database.js +2 -2
  131. package/ddl/drop-table.d.ts +4 -4
  132. package/ddl/drop-table.js +2 -2
  133. package/ddl/drop-user.d.ts +4 -4
  134. package/ddl/drop-user.js +2 -2
  135. package/ddl/foreign-key-constraint.d.ts +19 -19
  136. package/ddl/foreign-key-constraint.js +2 -2
  137. package/ddl/grant.d.ts +12 -12
  138. package/ddl/grant.js +2 -2
  139. package/ddl/index.d.ts +13 -13
  140. package/ddl/index.js +23 -23
  141. package/ddl/truncate.d.ts +3 -3
  142. package/ddl/truncate.js +2 -2
  143. package/dml/case-expression.d.ts +16 -16
  144. package/dml/case-expression.js +11 -11
  145. package/dml/delete.d.ts +8 -8
  146. package/dml/delete.js +2 -2
  147. package/dml/from.d.ts +4 -4
  148. package/dml/from.js +2 -2
  149. package/dml/group-by.d.ts +4 -4
  150. package/dml/group-by.js +2 -2
  151. package/dml/index.d.ts +11 -11
  152. package/dml/index.js +30 -30
  153. package/dml/insert.d.ts +14 -14
  154. package/dml/insert.js +2 -2
  155. package/dml/join.d.ts +7 -7
  156. package/dml/join.js +2 -2
  157. package/dml/order-by.d.ts +2 -2
  158. package/dml/order-by.js +2 -2
  159. package/dml/query-builder.d.ts +125 -106
  160. package/dml/query-builder.js +991 -793
  161. package/dml/query-builder.js.map +1 -1
  162. package/dml/query-repository.d.ts +84 -84
  163. package/dml/query-repository.js +239 -225
  164. package/dml/query-repository.js.map +1 -1
  165. package/dml/select.d.ts +44 -29
  166. package/dml/select.js +2 -2
  167. package/dml/set-options.d.ts +5 -5
  168. package/dml/set-options.js +2 -2
  169. package/dml/subquery.d.ts +5 -5
  170. package/dml/subquery.js +10 -10
  171. package/dml/update.d.ts +11 -11
  172. package/dml/update.js +2 -2
  173. package/expression/expression-token.d.ts +11 -11
  174. package/expression/expression-token.js +12 -12
  175. package/expression/expression.d.ts +6 -6
  176. package/expression/expression.js +2 -2
  177. package/expression/identifier.d.ts +7 -7
  178. package/expression/identifier.js +15 -15
  179. package/expression/index.d.ts +7 -7
  180. package/expression/index.js +25 -25
  181. package/expression/is-expression-token.d.ts +2 -2
  182. package/expression/is-expression-token.js +7 -7
  183. package/expression/key-val-expression.d.ts +7 -7
  184. package/expression/key-val-expression.js +2 -2
  185. package/expression/literal.d.ts +3 -3
  186. package/expression/literal.js +2 -2
  187. package/expression/logical.d.ts +28 -18
  188. package/expression/logical.js +54 -30
  189. package/expression/logical.js.map +1 -1
  190. package/expression/math.d.ts +17 -17
  191. package/expression/math.js +36 -36
  192. package/expression/raw.d.ts +8 -8
  193. package/expression/raw.js +16 -16
  194. package/expression/simple-expression.d.ts +8 -8
  195. package/expression/simple-expression.js +2 -2
  196. package/functions/function-aliases.d.ts +6 -4
  197. package/functions/function-aliases.js +16 -12
  198. package/functions/function-aliases.js.map +1 -1
  199. package/functions/function-token.d.ts +33 -29
  200. package/functions/function-token.js +19 -15
  201. package/functions/function-token.js.map +1 -1
  202. package/functions/functions.d.ts +23 -19
  203. package/functions/functions.js +126 -94
  204. package/functions/functions.js.map +1 -1
  205. package/functions/index.d.ts +4 -4
  206. package/functions/index.js +22 -22
  207. package/functions/is-database-function.d.ts +8 -8
  208. package/functions/is-database-function.js +14 -14
  209. package/functions/signatures/count.d.ts +14 -11
  210. package/functions/signatures/count.js +2 -2
  211. package/index.d.ts +16 -16
  212. package/index.js +32 -32
  213. package/migration/index.d.ts +3 -3
  214. package/migration/index.js +9 -9
  215. package/migration/migration-package.d.ts +14 -14
  216. package/migration/migration-package.js +10 -10
  217. package/migration/migration-record.d.ts +10 -10
  218. package/migration/migration-record.js +2 -2
  219. package/migration/migration-runner.d.ts +33 -33
  220. package/migration/migration-runner.js +180 -180
  221. package/migration/migration.d.ts +12 -12
  222. package/migration/migration.js +27 -27
  223. package/migration/migrations/001-create-migration-table.d.ts +8 -8
  224. package/migration/migrations/001-create-migration-table.js +54 -54
  225. package/migration/migrations/002-add-migration-package-column.d.ts +9 -9
  226. package/migration/migrations/002-add-migration-package-column.js +44 -44
  227. package/package.json +1 -1
  228. package/record/index.d.ts +1 -1
  229. package/record/index.js +17 -17
  230. package/record/record.d.ts +2 -2
  231. package/record/record.js +2 -2
  232. package/repository/index.d.ts +2 -2
  233. package/repository/index.js +5 -5
  234. package/repository/repository-options.d.ts +6 -6
  235. package/repository/repository-options.js +2 -2
  236. package/repository/repository.d.ts +29 -29
  237. package/repository/repository.js +68 -68
  238. package/schema/index.d.ts +3 -3
  239. package/schema/index.js +5 -5
  240. package/schema/schema-query-repository.d.ts +54 -54
  241. package/schema/schema-query-repository.js +159 -159
  242. package/schema/schema-table.d.ts +9 -9
  243. package/schema/schema-table.js +2 -2
  244. package/schema/schema.d.ts +4 -4
  245. package/schema/schema.js +2 -2
  246. package/seed/auto-seed.d.ts +9 -9
  247. package/seed/auto-seed.js +61 -61
  248. package/seed/create-seed-table.d.ts +8 -8
  249. package/seed/create-seed-table.js +64 -64
  250. package/seed/index.d.ts +4 -4
  251. package/seed/index.js +9 -9
  252. package/seed/seed-record.d.ts +11 -11
  253. package/seed/seed-record.js +2 -2
  254. package/seed/seed-runner.d.ts +20 -20
  255. package/seed/seed-runner.js +91 -91
  256. package/seed/seed.d.ts +12 -12
  257. package/seed/seed.js +27 -27
  258. package/tokens/index.d.ts +1 -1
  259. package/tokens/index.js +5 -5
  260. package/triggers/index.d.ts +2 -2
  261. package/triggers/index.js +18 -18
  262. package/triggers/prebuilt/index.d.ts +1 -1
  263. package/triggers/prebuilt/index.js +5 -5
  264. package/triggers/prebuilt/update-timestamp-trigger.d.ts +16 -16
  265. package/triggers/prebuilt/update-timestamp-trigger.js +24 -24
  266. package/triggers/trigger-options.d.ts +22 -22
  267. package/triggers/trigger-options.js +2 -2
  268. package/triggers/trigger.d.ts +19 -19
  269. package/triggers/trigger.js +23 -23
package/CHANGELOG.md CHANGED
@@ -1,3 +1,3 @@
1
- # riao-dbal - Changelog
2
-
3
- ## [1.0.1] Initial Release
1
+ # riao-dbal - Changelog
2
+
3
+ ## [1.0.1] Initial Release
package/LICENSE.md CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2022 riao-dbal and others
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2022 riao-dbal and others
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,148 +1,148 @@
1
- # riao-dbal
2
-
3
- [![npm version](https://badge.fury.io/js/%40riao%2Fdbal.svg)](https://badge.fury.io/js/%40riao%2Fdbal)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
-
6
- A powerful TypeScript Database Abstraction Layer (DBAL) that provides a unified interface for working with multiple database types including MySQL, PostgreSQL, MSSQL, and SQLite.
7
-
8
- ## Features
9
-
10
- - 🔄 **Multi-Database Support**: Work with multiple databases using the same API
11
- - 🏗️ **TypeScript First**: Full TypeScript support with type safety and autocompletion
12
- - 🔨 **Query Builder**: Fluent interface for building complex SQL queries
13
- - 📊 **Reporting & Analytics**: Built-in support for aggregations, window functions, and complex data analysis
14
- - 🚀 **Migrations**: Version control for your database schema
15
- - 📦 **Column Pack**: Ready-to-use column definitions for common fields like usernames, emails, and timestamps
16
- - 🌱 **Seeding**: Populate your database with test data
17
- - 🔍 **Schema Management**: Track and manage your database schema
18
- - 💰 **Transactions**: Support for database transactions
19
- - 🛠️ **DDL Operations**: Create, alter, and drop database objects
20
- - ⚡ **Database Functions**: Built-in support for common database functions
21
-
22
-
23
- ## Getting Started
24
-
25
- Read the [getting started guide](https://stateless-studio.atlassian.net/wiki/spaces/Riao/pages/294916/Guide).
26
-
27
- ## Preview
28
-
29
- ### Creating a new Database
30
-
31
- `npx riao db:create`
32
-
33
- [Database Setup Guide](https://stateless-studio.atlassian.net/wiki/spaces/Riao/pages/328113/Setup+a+Database)
34
-
35
- ### Creating a Migration
36
-
37
- `npx riao migration:create create-users-table`
38
-
39
- [Database Migration Guide](https://stateless-studio.atlassian.net/wiki/spaces/Riao/pages/328666/Building+a+Database+Schema)
40
-
41
- ```typescript
42
- import { Migration } from '@riao/dbal';
43
- import { ColumnType } from '@riao/dbal';
44
- import {
45
- BigIntKeyColumn,
46
- EmailColumn,
47
- UsernameColumn,
48
- PasswordColumn,
49
- CreateTimestampColumn,
50
- UpdateTimestampColumn,
51
- } from '@riao/dbal/column-pack';
52
-
53
- export default class Users extends Migration {
54
- override async up() {
55
- await this.ddl.createTable({
56
- name: 'users',
57
- ifNotExists: true,
58
- columns: [
59
- BigIntKeyColumn,
60
- UsernameColumn,
61
- EmailColumn,
62
- PasswordColumn,
63
- {
64
- name: 'balance',
65
- type: ColumnType.DECIMAL,
66
- significant: 15,
67
- decimal: 2,
68
- required: true,
69
- default: 10000.0,
70
- },
71
- CreateTimestampColumn,
72
- UpdateTimestampColumn,
73
- ],
74
- });
75
- }
76
-
77
- override async down() {
78
- await this.ddl.dropTable({
79
- tables: 'users',
80
- ifExists: true,
81
- });
82
- }
83
- }
84
-
85
- ```
86
-
87
- Run your migrations with
88
- `npx riao migration:run`
89
-
90
- ### Creating Repositories
91
-
92
- `src/users/user-repository.ts`
93
- ```typescript
94
- import { maindb } from '../../database/main';
95
-
96
- export interface User {
97
- id: number;
98
- username: string;
99
- email: string;
100
- password: string;
101
- balance: number;
102
- create_timestamp: Date;
103
- update_timestamp: Date;
104
- }
105
-
106
-
107
- export const users = maindb.getQueryRepository<User>({
108
- table: 'users'
109
- });
110
- ```
111
-
112
- [Model Repositories Guide](https://stateless-studio.atlassian.net/wiki/spaces/Riao/pages/753686/Model+Repositories)
113
-
114
- ### Queries
115
-
116
- ```typescript
117
-
118
- // Insert a record
119
- await users.insertOne({
120
- username: 'John Doe',
121
- email: 'john@example.com'
122
- });
123
-
124
- // Find records
125
- const results = await users.find({
126
- where: {
127
- email: 'john@example.com'
128
- }
129
- });
130
- ```
131
-
132
- [Query Guide](https://stateless-studio.atlassian.net/wiki/spaces/Riao/pages/99430/Querying+the+Database)
133
-
134
- ## Documentation
135
-
136
- For detailed documentation, please [read the docs](https://stateless-studio.atlassian.net/wiki/spaces/Riao/pages/295404/Docs)!
137
-
138
- ## Contributing
139
-
140
- We welcome contributions! Please see our [Contributing Guidelines](docs/contributing/contributing.md) for details.
141
-
142
- ## License
143
-
144
- This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
145
-
146
- ## Support
147
-
148
- If you encounter any issues or have questions, please [open an issue](https://github.com/riao-project/riao-dbal/issues) on our GitHub repository.
1
+ # riao-dbal
2
+
3
+ [![npm version](https://badge.fury.io/js/%40riao%2Fdbal.svg)](https://badge.fury.io/js/%40riao%2Fdbal)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ A powerful TypeScript Database Abstraction Layer (DBAL) that provides a unified interface for working with multiple database types including MySQL, PostgreSQL, MSSQL, and SQLite.
7
+
8
+ ## Features
9
+
10
+ - 🔄 **Multi-Database Support**: Work with multiple databases using the same API
11
+ - 🏗️ **TypeScript First**: Full TypeScript support with type safety and autocompletion
12
+ - 🔨 **Query Builder**: Fluent interface for building complex SQL queries
13
+ - 📊 **Reporting & Analytics**: Built-in support for aggregations, window functions, and complex data analysis
14
+ - 🚀 **Migrations**: Version control for your database schema
15
+ - 📦 **Column Pack**: Ready-to-use column definitions for common fields like usernames, emails, and timestamps
16
+ - 🌱 **Seeding**: Populate your database with test data
17
+ - 🔍 **Schema Management**: Track and manage your database schema
18
+ - 💰 **Transactions**: Support for database transactions
19
+ - 🛠️ **DDL Operations**: Create, alter, and drop database objects
20
+ - ⚡ **Database Functions**: Built-in support for common database functions
21
+
22
+
23
+ ## Getting Started
24
+
25
+ Read the [getting started guide](https://stateless-studio.atlassian.net/wiki/spaces/Riao/pages/294916/Guide).
26
+
27
+ ## Preview
28
+
29
+ ### Creating a new Database
30
+
31
+ `npx riao db:create`
32
+
33
+ [Database Setup Guide](https://stateless-studio.atlassian.net/wiki/spaces/Riao/pages/328113/Setup+a+Database)
34
+
35
+ ### Creating a Migration
36
+
37
+ `npx riao migration:create create-users-table`
38
+
39
+ [Database Migration Guide](https://stateless-studio.atlassian.net/wiki/spaces/Riao/pages/328666/Building+a+Database+Schema)
40
+
41
+ ```typescript
42
+ import { Migration } from '@riao/dbal';
43
+ import { ColumnType } from '@riao/dbal';
44
+ import {
45
+ BigIntKeyColumn,
46
+ EmailColumn,
47
+ UsernameColumn,
48
+ PasswordColumn,
49
+ CreateTimestampColumn,
50
+ UpdateTimestampColumn,
51
+ } from '@riao/dbal/column-pack';
52
+
53
+ export default class Users extends Migration {
54
+ override async up() {
55
+ await this.ddl.createTable({
56
+ name: 'users',
57
+ ifNotExists: true,
58
+ columns: [
59
+ BigIntKeyColumn,
60
+ UsernameColumn,
61
+ EmailColumn,
62
+ PasswordColumn,
63
+ {
64
+ name: 'balance',
65
+ type: ColumnType.DECIMAL,
66
+ significant: 15,
67
+ decimal: 2,
68
+ required: true,
69
+ default: 10000.0,
70
+ },
71
+ CreateTimestampColumn,
72
+ UpdateTimestampColumn,
73
+ ],
74
+ });
75
+ }
76
+
77
+ override async down() {
78
+ await this.ddl.dropTable({
79
+ tables: 'users',
80
+ ifExists: true,
81
+ });
82
+ }
83
+ }
84
+
85
+ ```
86
+
87
+ Run your migrations with
88
+ `npx riao migration:run`
89
+
90
+ ### Creating Repositories
91
+
92
+ `src/users/user-repository.ts`
93
+ ```typescript
94
+ import { maindb } from '../../database/main';
95
+
96
+ export interface User {
97
+ id: number;
98
+ username: string;
99
+ email: string;
100
+ password: string;
101
+ balance: number;
102
+ create_timestamp: Date;
103
+ update_timestamp: Date;
104
+ }
105
+
106
+
107
+ export const users = maindb.getQueryRepository<User>({
108
+ table: 'users'
109
+ });
110
+ ```
111
+
112
+ [Model Repositories Guide](https://stateless-studio.atlassian.net/wiki/spaces/Riao/pages/753686/Model+Repositories)
113
+
114
+ ### Queries
115
+
116
+ ```typescript
117
+
118
+ // Insert a record
119
+ await users.insertOne({
120
+ username: 'John Doe',
121
+ email: 'john@example.com'
122
+ });
123
+
124
+ // Find records
125
+ const results = await users.find({
126
+ where: {
127
+ email: 'john@example.com'
128
+ }
129
+ });
130
+ ```
131
+
132
+ [Query Guide](https://stateless-studio.atlassian.net/wiki/spaces/Riao/pages/99430/Querying+the+Database)
133
+
134
+ ## Documentation
135
+
136
+ For detailed documentation, please [read the docs](https://stateless-studio.atlassian.net/wiki/spaces/Riao/pages/295404/Docs)!
137
+
138
+ ## Contributing
139
+
140
+ We welcome contributions! Please see our [Contributing Guidelines](docs/contributing/contributing.md) for details.
141
+
142
+ ## License
143
+
144
+ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
145
+
146
+ ## Support
147
+
148
+ If you encounter any issues or have questions, please [open an issue](https://github.com/riao-project/riao-dbal/issues) on our GitHub repository.
@@ -1,7 +1,7 @@
1
- import { DatabaseQueryOptions } from '../database';
2
- export declare abstract class Builder {
3
- next?: typeof this;
4
- createNext(): this;
5
- getQueries(): DatabaseQueryOptions[];
6
- abstract toDatabaseQuery(): DatabaseQueryOptions;
7
- }
1
+ import { DatabaseQueryOptions } from '../database';
2
+ export declare abstract class Builder {
3
+ next?: typeof this;
4
+ createNext(): this;
5
+ getQueries(): DatabaseQueryOptions[];
6
+ abstract toDatabaseQuery(): DatabaseQueryOptions;
7
+ }
@@ -1,20 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Builder = void 0;
4
- class Builder {
5
- createNext() {
6
- this.next = new this.constructor();
7
- return this.next;
8
- }
9
- getQueries() {
10
- const queries = [this.toDatabaseQuery()];
11
- let i = this.next;
12
- while (i) {
13
- queries.push(i.toDatabaseQuery());
14
- i = i.next;
15
- }
16
- return queries;
17
- }
18
- }
19
- exports.Builder = Builder;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Builder = void 0;
4
+ class Builder {
5
+ createNext() {
6
+ this.next = new this.constructor();
7
+ return this.next;
8
+ }
9
+ getQueries() {
10
+ const queries = [this.toDatabaseQuery()];
11
+ let i = this.next;
12
+ while (i) {
13
+ queries.push(i.toDatabaseQuery());
14
+ i = i.next;
15
+ }
16
+ return queries;
17
+ }
18
+ }
19
+ exports.Builder = Builder;
20
20
  //# sourceMappingURL=builder.js.map
@@ -1,2 +1,2 @@
1
- export { Builder } from './builder';
2
- export { SqlBuilder } from './sql-builder';
1
+ export { Builder } from './builder';
2
+ export { SqlBuilder } from './sql-builder';
package/builder/index.js CHANGED
@@ -1,8 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SqlBuilder = exports.Builder = void 0;
4
- var builder_1 = require("./builder");
5
- Object.defineProperty(exports, "Builder", { enumerable: true, get: function () { return builder_1.Builder; } });
6
- var sql_builder_1 = require("./sql-builder");
7
- Object.defineProperty(exports, "SqlBuilder", { enumerable: true, get: function () { return sql_builder_1.SqlBuilder; } });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SqlBuilder = exports.Builder = void 0;
4
+ var builder_1 = require("./builder");
5
+ Object.defineProperty(exports, "Builder", { enumerable: true, get: function () { return builder_1.Builder; } });
6
+ var sql_builder_1 = require("./sql-builder");
7
+ Object.defineProperty(exports, "SqlBuilder", { enumerable: true, get: function () { return sql_builder_1.SqlBuilder; } });
8
8
  //# sourceMappingURL=index.js.map
@@ -1,53 +1,54 @@
1
- import { DatabaseQueryOptions } from '../database/driver-query';
2
- import { Builder } from './builder';
3
- export declare class SqlBuilder extends Builder {
4
- protected sql: string;
5
- protected params: any[];
6
- protected usePlaceholders: boolean;
7
- operators: {
8
- closeParens: string;
9
- openParens: string;
10
- endStatement: string;
11
- equals: string;
12
- like: string;
13
- notEqual: string;
14
- negate: string;
15
- lt: string;
16
- lte: string;
17
- gt: string;
18
- gte: string;
19
- and: string;
20
- or: string;
21
- null: string;
22
- is: string;
23
- in: string;
24
- between: string;
25
- openEnclosure: string;
26
- closeEnclosure: string;
27
- addition: string;
28
- subtraction: string;
29
- multiplication: string;
30
- division: string;
31
- modulo: string;
32
- };
33
- toDatabaseQuery(): DatabaseQueryOptions;
34
- append(str: string): this;
35
- appendParams(params: any[]): void;
36
- space(): this;
37
- commaSeparate(strings: string[]): this;
38
- openParens(): this;
39
- closeParens(): this;
40
- trimEnd(s?: string): this;
41
- endStatement(): this;
42
- encloseString(str: string): string;
43
- getEnclosedName(str: string): string;
44
- tableName(name: string): this;
45
- columnName(name: string): this;
46
- enablePlaceholders(): this;
47
- disablePlaceholders(): this;
48
- appendPlaceholder(value: any): this;
49
- placeholder(value: any): this;
50
- appendValue(value: any): this;
51
- appendNull(): this;
52
- appendStringValue(value: string): this;
53
- }
1
+ import { DatabaseQueryOptions } from '../database/driver-query';
2
+ import { Builder } from './builder';
3
+ export declare class SqlBuilder extends Builder {
4
+ protected sql: string;
5
+ protected params: any[];
6
+ protected usePlaceholders: boolean;
7
+ operators: {
8
+ closeParens: string;
9
+ openParens: string;
10
+ endStatement: string;
11
+ equals: string;
12
+ like: string;
13
+ notEqual: string;
14
+ negate: string;
15
+ lt: string;
16
+ lte: string;
17
+ gt: string;
18
+ gte: string;
19
+ and: string;
20
+ or: string;
21
+ null: string;
22
+ is: string;
23
+ in: string;
24
+ between: string;
25
+ openEnclosure: string;
26
+ closeEnclosure: string;
27
+ addition: string;
28
+ subtraction: string;
29
+ multiplication: string;
30
+ division: string;
31
+ modulo: string;
32
+ };
33
+ toDatabaseQuery(): DatabaseQueryOptions;
34
+ prepend(str: string): this;
35
+ append(str: string): this;
36
+ appendParams(params: any[]): void;
37
+ space(): this;
38
+ commaSeparate(strings: string[]): this;
39
+ openParens(): this;
40
+ closeParens(): this;
41
+ trimEnd(s?: string): this;
42
+ endStatement(): this;
43
+ encloseString(str: string): string;
44
+ getEnclosedName(str: string): string;
45
+ tableName(name: string): this;
46
+ columnName(name: string): this;
47
+ enablePlaceholders(): this;
48
+ disablePlaceholders(): this;
49
+ appendPlaceholder(value: any): this;
50
+ placeholder(value: any): this;
51
+ appendValue(value: any): this;
52
+ appendNull(): this;
53
+ appendStringValue(value: string): this;
54
+ }