@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.
- package/CHANGELOG.md +3 -3
- package/LICENSE.md +20 -20
- package/README.md +148 -148
- package/builder/builder.d.ts +7 -7
- package/builder/builder.js +19 -19
- package/builder/index.d.ts +2 -2
- package/builder/index.js +7 -7
- package/builder/sql-builder.d.ts +54 -53
- package/builder/sql-builder.js +161 -157
- package/builder/sql-builder.js.map +1 -1
- package/builder/statement-builder.d.ts +12 -12
- package/builder/statement-builder.js +32 -32
- package/column/column-options.d.ts +156 -156
- package/column/column-options.js +2 -2
- package/column/column-type.d.ts +18 -18
- package/column/column-type.js +27 -27
- package/column/column-values.d.ts +34 -34
- package/column/column-values.js +2 -2
- package/column/create-column-template.d.ts +11 -0
- package/column/create-column-template.js +57 -0
- package/column/create-column-template.js.map +1 -0
- package/column/index.d.ts +4 -3
- package/column/index.js +20 -19
- package/column/index.js.map +1 -1
- package/column-pack/date-time/create-timestamp-column.d.ts +2 -2
- package/column-pack/date-time/create-timestamp-column.js +10 -10
- package/column-pack/date-time/index.d.ts +2 -2
- package/column-pack/date-time/index.js +7 -7
- package/column-pack/date-time/update-timestamp-column.d.ts +2 -2
- package/column-pack/date-time/update-timestamp-column.js +14 -14
- package/column-pack/index.d.ts +6 -6
- package/column-pack/index.js +22 -22
- package/column-pack/keys/big-int-key-column.d.ts +2 -2
- package/column-pack/keys/big-int-key-column.js +10 -10
- package/column-pack/keys/index.d.ts +3 -3
- package/column-pack/keys/index.js +9 -9
- package/column-pack/keys/int-key-column.d.ts +2 -2
- package/column-pack/keys/int-key-column.js +10 -10
- package/column-pack/keys/uuid-key-column.d.ts +2 -2
- package/column-pack/keys/uuid-key-column.js +11 -11
- package/column-pack/person/date-of-birth-column.d.ts +2 -2
- package/column-pack/person/date-of-birth-column.js +8 -8
- package/column-pack/person/first-name-column.d.ts +2 -2
- package/column-pack/person/first-name-column.js +9 -9
- package/column-pack/person/index.d.ts +3 -3
- package/column-pack/person/index.js +9 -9
- package/column-pack/person/last-name-column.d.ts +2 -2
- package/column-pack/person/last-name-column.js +9 -9
- package/column-pack/resource/content-column.d.ts +2 -2
- package/column-pack/resource/content-column.js +9 -9
- package/column-pack/resource/description-column.d.ts +2 -2
- package/column-pack/resource/description-column.js +9 -9
- package/column-pack/resource/index.d.ts +6 -6
- package/column-pack/resource/index.js +15 -15
- package/column-pack/resource/is-active-column.d.ts +2 -2
- package/column-pack/resource/is-active-column.js +9 -9
- package/column-pack/resource/name-column.d.ts +2 -2
- package/column-pack/resource/name-column.js +10 -10
- package/column-pack/resource/path-column.d.ts +2 -2
- package/column-pack/resource/path-column.js +11 -11
- package/column-pack/resource/title-column.d.ts +2 -2
- package/column-pack/resource/title-column.js +10 -10
- package/column-pack/system/filename-column.d.ts +2 -2
- package/column-pack/system/filename-column.js +9 -9
- package/column-pack/system/filepath-column.d.ts +2 -2
- package/column-pack/system/filepath-column.js +9 -9
- package/column-pack/system/index.d.ts +4 -4
- package/column-pack/system/index.js +11 -11
- package/column-pack/system/ip-address-column.d.ts +2 -2
- package/column-pack/system/ip-address-column.js +9 -9
- package/column-pack/system/url-column.d.ts +3 -3
- package/column-pack/system/url-column.js +13 -13
- package/column-pack/user/email-column.d.ts +2 -2
- package/column-pack/user/email-column.js +11 -11
- package/column-pack/user/index.d.ts +4 -4
- package/column-pack/user/index.js +11 -11
- package/column-pack/user/password-column.d.ts +2 -2
- package/column-pack/user/password-column.js +10 -10
- package/column-pack/user/temp-email-column.d.ts +2 -2
- package/column-pack/user/temp-email-column.js +5 -5
- package/column-pack/user/username-column.d.ts +2 -2
- package/column-pack/user/username-column.js +11 -11
- package/comparison/comparison-aliases.d.ts +10 -10
- package/comparison/comparison-aliases.js +40 -40
- package/comparison/comparison-token.d.ts +17 -17
- package/comparison/comparison-token.js +15 -15
- package/comparison/comparison.d.ts +13 -13
- package/comparison/comparison.js +71 -71
- package/comparison/index.d.ts +4 -4
- package/comparison/index.js +24 -24
- package/comparison/is-comparison-token.d.ts +2 -2
- package/comparison/is-comparison-token.js +8 -8
- package/config/configure-db.d.ts +14 -14
- package/config/configure-db.js +18 -18
- package/config/database-env.d.ts +16 -16
- package/config/database-env.js +14 -14
- package/config/index.d.ts +2 -2
- package/config/index.js +7 -7
- package/database/connection-options.d.ts +7 -7
- package/database/connection-options.js +2 -2
- package/database/database.d.ts +204 -204
- package/database/database.js +330 -330
- package/database/driver-query.d.ts +10 -10
- package/database/driver-query.js +2 -2
- package/database/driver.d.ts +12 -12
- package/database/driver.js +47 -47
- package/database/get-database-path.d.ts +6 -6
- package/database/get-database-path.js +12 -12
- package/database/index.d.ts +7 -7
- package/database/index.js +26 -26
- package/database/load-database.d.ts +9 -9
- package/database/load-database.js +36 -36
- package/database/transaction.d.ts +8 -8
- package/database/transaction.js +2 -2
- package/ddl/alter-table.d.ts +26 -26
- package/ddl/alter-table.js +2 -2
- package/ddl/create-database.d.ts +3 -3
- package/ddl/create-database.js +2 -2
- package/ddl/create-index.d.ts +5 -5
- package/ddl/create-index.js +2 -2
- package/ddl/create-table.d.ts +8 -8
- package/ddl/create-table.js +2 -2
- package/ddl/create-user.d.ts +4 -4
- package/ddl/create-user.js +2 -2
- package/ddl/ddl-builder.d.ts +96 -96
- package/ddl/ddl-builder.js +565 -565
- package/ddl/ddl-repository.d.ts +135 -135
- package/ddl/ddl-repository.js +228 -228
- package/ddl/drop-database.d.ts +4 -4
- package/ddl/drop-database.js +2 -2
- package/ddl/drop-table.d.ts +4 -4
- package/ddl/drop-table.js +2 -2
- package/ddl/drop-user.d.ts +4 -4
- package/ddl/drop-user.js +2 -2
- package/ddl/foreign-key-constraint.d.ts +19 -19
- package/ddl/foreign-key-constraint.js +2 -2
- package/ddl/grant.d.ts +12 -12
- package/ddl/grant.js +2 -2
- package/ddl/index.d.ts +13 -13
- package/ddl/index.js +23 -23
- package/ddl/truncate.d.ts +3 -3
- package/ddl/truncate.js +2 -2
- package/dml/case-expression.d.ts +16 -16
- package/dml/case-expression.js +11 -11
- package/dml/delete.d.ts +8 -8
- package/dml/delete.js +2 -2
- package/dml/from.d.ts +4 -4
- package/dml/from.js +2 -2
- package/dml/group-by.d.ts +4 -4
- package/dml/group-by.js +2 -2
- package/dml/index.d.ts +11 -11
- package/dml/index.js +30 -30
- package/dml/insert.d.ts +14 -14
- package/dml/insert.js +2 -2
- package/dml/join.d.ts +7 -7
- package/dml/join.js +2 -2
- package/dml/order-by.d.ts +2 -2
- package/dml/order-by.js +2 -2
- package/dml/query-builder.d.ts +125 -106
- package/dml/query-builder.js +991 -793
- package/dml/query-builder.js.map +1 -1
- package/dml/query-repository.d.ts +84 -84
- package/dml/query-repository.js +239 -225
- package/dml/query-repository.js.map +1 -1
- package/dml/select.d.ts +44 -29
- package/dml/select.js +2 -2
- package/dml/set-options.d.ts +5 -5
- package/dml/set-options.js +2 -2
- package/dml/subquery.d.ts +5 -5
- package/dml/subquery.js +10 -10
- package/dml/update.d.ts +11 -11
- package/dml/update.js +2 -2
- package/expression/expression-token.d.ts +11 -11
- package/expression/expression-token.js +12 -12
- package/expression/expression.d.ts +6 -6
- package/expression/expression.js +2 -2
- package/expression/identifier.d.ts +7 -7
- package/expression/identifier.js +15 -15
- package/expression/index.d.ts +7 -7
- package/expression/index.js +25 -25
- package/expression/is-expression-token.d.ts +2 -2
- package/expression/is-expression-token.js +7 -7
- package/expression/key-val-expression.d.ts +7 -7
- package/expression/key-val-expression.js +2 -2
- package/expression/literal.d.ts +3 -3
- package/expression/literal.js +2 -2
- package/expression/logical.d.ts +28 -18
- package/expression/logical.js +54 -30
- package/expression/logical.js.map +1 -1
- package/expression/math.d.ts +17 -17
- package/expression/math.js +36 -36
- package/expression/raw.d.ts +8 -8
- package/expression/raw.js +16 -16
- package/expression/simple-expression.d.ts +8 -8
- package/expression/simple-expression.js +2 -2
- package/functions/function-aliases.d.ts +6 -4
- package/functions/function-aliases.js +16 -12
- package/functions/function-aliases.js.map +1 -1
- package/functions/function-token.d.ts +33 -29
- package/functions/function-token.js +19 -15
- package/functions/function-token.js.map +1 -1
- package/functions/functions.d.ts +23 -19
- package/functions/functions.js +126 -94
- package/functions/functions.js.map +1 -1
- package/functions/index.d.ts +4 -4
- package/functions/index.js +22 -22
- package/functions/is-database-function.d.ts +8 -8
- package/functions/is-database-function.js +14 -14
- package/functions/signatures/count.d.ts +14 -11
- package/functions/signatures/count.js +2 -2
- package/index.d.ts +16 -16
- package/index.js +32 -32
- package/migration/index.d.ts +3 -3
- package/migration/index.js +9 -9
- package/migration/migration-package.d.ts +14 -14
- package/migration/migration-package.js +10 -10
- package/migration/migration-record.d.ts +10 -10
- package/migration/migration-record.js +2 -2
- package/migration/migration-runner.d.ts +33 -33
- package/migration/migration-runner.js +180 -180
- package/migration/migration.d.ts +12 -12
- package/migration/migration.js +27 -27
- package/migration/migrations/001-create-migration-table.d.ts +8 -8
- package/migration/migrations/001-create-migration-table.js +54 -54
- package/migration/migrations/002-add-migration-package-column.d.ts +9 -9
- package/migration/migrations/002-add-migration-package-column.js +44 -44
- package/package.json +1 -1
- package/record/index.d.ts +1 -1
- package/record/index.js +17 -17
- package/record/record.d.ts +2 -2
- package/record/record.js +2 -2
- package/repository/index.d.ts +2 -2
- package/repository/index.js +5 -5
- package/repository/repository-options.d.ts +6 -6
- package/repository/repository-options.js +2 -2
- package/repository/repository.d.ts +29 -29
- package/repository/repository.js +68 -68
- package/schema/index.d.ts +3 -3
- package/schema/index.js +5 -5
- package/schema/schema-query-repository.d.ts +54 -54
- package/schema/schema-query-repository.js +159 -159
- package/schema/schema-table.d.ts +9 -9
- package/schema/schema-table.js +2 -2
- package/schema/schema.d.ts +4 -4
- package/schema/schema.js +2 -2
- package/seed/auto-seed.d.ts +9 -9
- package/seed/auto-seed.js +61 -61
- package/seed/create-seed-table.d.ts +8 -8
- package/seed/create-seed-table.js +64 -64
- package/seed/index.d.ts +4 -4
- package/seed/index.js +9 -9
- package/seed/seed-record.d.ts +11 -11
- package/seed/seed-record.js +2 -2
- package/seed/seed-runner.d.ts +20 -20
- package/seed/seed-runner.js +91 -91
- package/seed/seed.d.ts +12 -12
- package/seed/seed.js +27 -27
- package/tokens/index.d.ts +1 -1
- package/tokens/index.js +5 -5
- package/triggers/index.d.ts +2 -2
- package/triggers/index.js +18 -18
- package/triggers/prebuilt/index.d.ts +1 -1
- package/triggers/prebuilt/index.js +5 -5
- package/triggers/prebuilt/update-timestamp-trigger.d.ts +16 -16
- package/triggers/prebuilt/update-timestamp-trigger.js +24 -24
- package/triggers/trigger-options.d.ts +22 -22
- package/triggers/trigger-options.js +2 -2
- package/triggers/trigger.d.ts +19 -19
- 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
|
-
[](https://badge.fury.io/js/%40riao%2Fdbal)
|
|
4
|
-
[](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
|
+
[](https://badge.fury.io/js/%40riao%2Fdbal)
|
|
4
|
+
[](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.
|
package/builder/builder.d.ts
CHANGED
|
@@ -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
|
+
}
|
package/builder/builder.js
CHANGED
|
@@ -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
|
package/builder/index.d.ts
CHANGED
|
@@ -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
|
package/builder/sql-builder.d.ts
CHANGED
|
@@ -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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
}
|