@neogroup/neorm 0.0.1 → 0.0.3
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/README.md +36 -35
- package/dist/database/Connection.d.ts +10 -0
- package/dist/database/Connection.js +3 -0
- package/dist/database/Connection.js.map +1 -0
- package/dist/database/DB.d.ts +63 -0
- package/dist/database/DB.js +247 -0
- package/dist/database/DB.js.map +1 -0
- package/dist/database/DataConnection.d.ts +24 -0
- package/dist/database/DataConnection.js +99 -0
- package/dist/database/DataConnection.js.map +1 -0
- package/dist/database/DataSet.d.ts +3 -0
- package/dist/database/DataSet.js +3 -0
- package/dist/database/DataSet.js.map +1 -0
- package/dist/database/DataSource.d.ts +23 -0
- package/dist/database/DataSource.js +56 -0
- package/dist/database/DataSource.js.map +1 -0
- package/dist/database/DataTable.d.ts +19 -0
- package/dist/database/DataTable.js +75 -0
- package/dist/database/DataTable.js.map +1 -0
- package/dist/database/index.d.ts +8 -0
- package/dist/database/index.js +25 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/query/DeleteQuery.d.ts +8 -0
- package/dist/database/query/DeleteQuery.js +17 -0
- package/dist/database/query/DeleteQuery.js.map +1 -0
- package/dist/database/query/InsertQuery.d.ts +8 -0
- package/dist/database/query/InsertQuery.js +17 -0
- package/dist/database/query/InsertQuery.js.map +1 -0
- package/dist/database/query/Query.d.ts +2 -0
- package/dist/database/query/Query.js +7 -0
- package/dist/database/query/Query.js.map +1 -0
- package/dist/database/query/QueryTable.d.ts +7 -0
- package/dist/database/query/QueryTable.js +3 -0
- package/dist/database/query/QueryTable.js.map +1 -0
- package/dist/database/query/SelectQuery.d.ts +9 -0
- package/dist/database/query/SelectQuery.js +33 -0
- package/dist/database/query/SelectQuery.js.map +1 -0
- package/dist/database/query/Statement.d.ts +4 -0
- package/dist/database/query/Statement.js +3 -0
- package/dist/database/query/Statement.js.map +1 -0
- package/dist/database/query/UpdateQuery.d.ts +8 -0
- package/dist/database/query/UpdateQuery.js +17 -0
- package/dist/database/query/UpdateQuery.js.map +1 -0
- package/dist/database/query/builders/DefaultQueryBuilder.d.ts +87 -0
- package/dist/database/query/builders/DefaultQueryBuilder.js +524 -0
- package/dist/database/query/builders/DefaultQueryBuilder.js.map +1 -0
- package/dist/database/query/builders/QueryBuilder.d.ts +5 -0
- package/dist/database/query/builders/QueryBuilder.js +7 -0
- package/dist/database/query/builders/QueryBuilder.js.map +1 -0
- package/dist/database/query/builders/index.d.ts +2 -0
- package/dist/database/query/builders/index.js +19 -0
- package/dist/database/query/builders/index.js.map +1 -0
- package/dist/database/query/conditions/BasicCondition.d.ts +6 -0
- package/dist/database/query/conditions/BasicCondition.js +3 -0
- package/dist/database/query/conditions/BasicCondition.js.map +1 -0
- package/dist/database/query/conditions/ColumnCondition.d.ts +6 -0
- package/dist/database/query/conditions/ColumnCondition.js +3 -0
- package/dist/database/query/conditions/ColumnCondition.js.map +1 -0
- package/dist/database/query/conditions/Condition.d.ts +5 -0
- package/dist/database/query/conditions/Condition.js +3 -0
- package/dist/database/query/conditions/Condition.js.map +1 -0
- package/dist/database/query/conditions/ConditionConnector.d.ts +4 -0
- package/dist/database/query/conditions/ConditionConnector.js +9 -0
- package/dist/database/query/conditions/ConditionConnector.js.map +1 -0
- package/dist/database/query/conditions/ConditionGroup.d.ts +40 -0
- package/dist/database/query/conditions/ConditionGroup.js +138 -0
- package/dist/database/query/conditions/ConditionGroup.js.map +1 -0
- package/dist/database/query/conditions/ConnectedCondition.d.ts +6 -0
- package/dist/database/query/conditions/ConnectedCondition.js +3 -0
- package/dist/database/query/conditions/ConnectedCondition.js.map +1 -0
- package/dist/database/query/conditions/RawCondition.d.ts +4 -0
- package/dist/database/query/conditions/RawCondition.js +3 -0
- package/dist/database/query/conditions/RawCondition.js.map +1 -0
- package/dist/database/query/conditions/index.d.ts +7 -0
- package/dist/database/query/conditions/index.js +24 -0
- package/dist/database/query/conditions/index.js.map +1 -0
- package/dist/database/query/features/HasAlias.d.ts +6 -0
- package/dist/database/query/features/HasAlias.js +17 -0
- package/dist/database/query/features/HasAlias.js.map +1 -0
- package/dist/database/query/features/HasDistinct.d.ts +6 -0
- package/dist/database/query/features/HasDistinct.js +20 -0
- package/dist/database/query/features/HasDistinct.js.map +1 -0
- package/dist/database/query/features/HasFieldValues.d.ts +9 -0
- package/dist/database/query/features/HasFieldValues.js +27 -0
- package/dist/database/query/features/HasFieldValues.js.map +1 -0
- package/dist/database/query/features/HasGroupByFields.d.ts +7 -0
- package/dist/database/query/features/HasGroupByFields.js +21 -0
- package/dist/database/query/features/HasGroupByFields.js.map +1 -0
- package/dist/database/query/features/HasHavingConditions.d.ts +13 -0
- package/dist/database/query/features/HasHavingConditions.js +28 -0
- package/dist/database/query/features/HasHavingConditions.js.map +1 -0
- package/dist/database/query/features/HasJoins.d.ts +41 -0
- package/dist/database/query/features/HasJoins.js +66 -0
- package/dist/database/query/features/HasJoins.js.map +1 -0
- package/dist/database/query/features/HasLimit.d.ts +6 -0
- package/dist/database/query/features/HasLimit.js +20 -0
- package/dist/database/query/features/HasLimit.js.map +1 -0
- package/dist/database/query/features/HasOffset.d.ts +6 -0
- package/dist/database/query/features/HasOffset.js +20 -0
- package/dist/database/query/features/HasOffset.js.map +1 -0
- package/dist/database/query/features/HasOrderByFields.d.ts +15 -0
- package/dist/database/query/features/HasOrderByFields.js +38 -0
- package/dist/database/query/features/HasOrderByFields.js.map +1 -0
- package/dist/database/query/features/HasSelectFields.d.ts +11 -0
- package/dist/database/query/features/HasSelectFields.js +21 -0
- package/dist/database/query/features/HasSelectFields.js.map +1 -0
- package/dist/database/query/features/HasTable.d.ts +7 -0
- package/dist/database/query/features/HasTable.js +20 -0
- package/dist/database/query/features/HasTable.js.map +1 -0
- package/dist/database/query/features/HasUnions.d.ts +13 -0
- package/dist/database/query/features/HasUnions.js +21 -0
- package/dist/database/query/features/HasUnions.js.map +1 -0
- package/dist/database/query/features/HasWhen.d.ts +3 -0
- package/dist/database/query/features/HasWhen.js +13 -0
- package/dist/database/query/features/HasWhen.js.map +1 -0
- package/dist/database/query/features/HasWhereConditions.d.ts +35 -0
- package/dist/database/query/features/HasWhereConditions.js +92 -0
- package/dist/database/query/features/HasWhereConditions.js.map +1 -0
- package/dist/database/query/features/index.d.ts +14 -0
- package/dist/database/query/features/index.js +31 -0
- package/dist/database/query/features/index.js.map +1 -0
- package/dist/database/query/fields/BasicField.d.ts +5 -0
- package/dist/database/query/fields/BasicField.js +3 -0
- package/dist/database/query/fields/BasicField.js.map +1 -0
- package/dist/database/query/fields/Field.d.ts +3 -0
- package/dist/database/query/fields/Field.js +3 -0
- package/dist/database/query/fields/Field.js.map +1 -0
- package/dist/database/query/fields/RawField.d.ts +1 -0
- package/dist/database/query/fields/RawField.js +3 -0
- package/dist/database/query/fields/RawField.js.map +1 -0
- package/dist/database/query/fields/index.d.ts +3 -0
- package/dist/database/query/fields/index.js +20 -0
- package/dist/database/query/fields/index.js.map +1 -0
- package/dist/database/query/index.d.ts +11 -0
- package/dist/database/query/index.js +28 -0
- package/dist/database/query/index.js.map +1 -0
- package/dist/database/sources/index.d.ts +3 -0
- package/dist/database/sources/index.js +20 -0
- package/dist/database/sources/index.js.map +1 -0
- package/dist/database/sources/mysql/MysqlConnection.d.ts +14 -0
- package/dist/database/sources/mysql/MysqlConnection.js +36 -0
- package/dist/database/sources/mysql/MysqlConnection.js.map +1 -0
- package/dist/database/sources/mysql/MysqlDataSource.d.ts +24 -0
- package/dist/database/sources/mysql/MysqlDataSource.js +72 -0
- package/dist/database/sources/mysql/MysqlDataSource.js.map +1 -0
- package/dist/database/sources/mysql/MysqlQueryBuilder.d.ts +6 -0
- package/dist/database/sources/mysql/MysqlQueryBuilder.js +28 -0
- package/dist/database/sources/mysql/MysqlQueryBuilder.js.map +1 -0
- package/dist/database/sources/mysql/index.d.ts +3 -0
- package/dist/database/sources/mysql/index.js +20 -0
- package/dist/database/sources/mysql/index.js.map +1 -0
- package/dist/database/sources/postgres/PostgresConnection.d.ts +13 -0
- package/dist/database/sources/postgres/PostgresConnection.js +40 -0
- package/dist/database/sources/postgres/PostgresConnection.js.map +1 -0
- package/dist/database/sources/postgres/PostgresDataSource.d.ts +24 -0
- package/dist/database/sources/postgres/PostgresDataSource.js +73 -0
- package/dist/database/sources/postgres/PostgresDataSource.js.map +1 -0
- package/dist/database/sources/postgres/PostgresQueryBuilder.d.ts +5 -0
- package/dist/database/sources/postgres/PostgresQueryBuilder.js +13 -0
- package/dist/database/sources/postgres/PostgresQueryBuilder.js.map +1 -0
- package/dist/database/sources/postgres/index.d.ts +2 -0
- package/dist/database/sources/postgres/index.js +19 -0
- package/dist/database/sources/postgres/index.js.map +1 -0
- package/dist/database/sources/sqlite/SqliteConnection.d.ts +14 -0
- package/dist/database/sources/sqlite/SqliteConnection.js +37 -0
- package/dist/database/sources/sqlite/SqliteConnection.js.map +1 -0
- package/dist/database/sources/sqlite/SqliteDataSource.d.ts +11 -0
- package/dist/database/sources/sqlite/SqliteDataSource.js +34 -0
- package/dist/database/sources/sqlite/SqliteDataSource.js.map +1 -0
- package/dist/database/sources/sqlite/SqliteQueryBuilder.d.ts +6 -0
- package/dist/database/sources/sqlite/SqliteQueryBuilder.js +23 -0
- package/dist/database/sources/sqlite/SqliteQueryBuilder.js.map +1 -0
- package/dist/database/sources/sqlite/index.d.ts +3 -0
- package/dist/database/sources/sqlite/index.js +20 -0
- package/dist/database/sources/sqlite/index.js.map +1 -0
- package/dist/entities/BaseEntity.d.ts +76 -0
- package/dist/entities/BaseEntity.js +208 -0
- package/dist/entities/BaseEntity.js.map +1 -0
- package/dist/entities/CastType.d.ts +1 -0
- package/dist/entities/CastType.js +3 -0
- package/dist/entities/CastType.js.map +1 -0
- package/dist/entities/Entities.d.ts +14 -0
- package/dist/entities/Entities.js +85 -0
- package/dist/entities/Entities.js.map +1 -0
- package/dist/entities/EntityQuery.d.ts +60 -0
- package/dist/entities/EntityQuery.js +305 -0
- package/dist/entities/EntityQuery.js.map +1 -0
- package/dist/entities/RelationshipType.d.ts +1 -0
- package/dist/entities/RelationshipType.js +3 -0
- package/dist/entities/RelationshipType.js.map +1 -0
- package/dist/entities/decorators/BelongsTo.d.ts +2 -0
- package/dist/entities/decorators/BelongsTo.js +15 -0
- package/dist/entities/decorators/BelongsTo.js.map +1 -0
- package/dist/entities/decorators/Column.d.ts +13 -0
- package/dist/entities/decorators/Column.js +12 -0
- package/dist/entities/decorators/Column.js.map +1 -0
- package/dist/entities/decorators/Entity.d.ts +20 -0
- package/dist/entities/decorators/Entity.js +50 -0
- package/dist/entities/decorators/Entity.js.map +1 -0
- package/dist/entities/decorators/HasMany.d.ts +2 -0
- package/dist/entities/decorators/HasMany.js +15 -0
- package/dist/entities/decorators/HasMany.js.map +1 -0
- package/dist/entities/decorators/HasManyThrough.d.ts +2 -0
- package/dist/entities/decorators/HasManyThrough.js +23 -0
- package/dist/entities/decorators/HasManyThrough.js.map +1 -0
- package/dist/entities/decorators/HasOne.d.ts +2 -0
- package/dist/entities/decorators/HasOne.js +12 -0
- package/dist/entities/decorators/HasOne.js.map +1 -0
- package/dist/entities/decorators/HasOneThrough.d.ts +2 -0
- package/dist/entities/decorators/HasOneThrough.js +23 -0
- package/dist/entities/decorators/HasOneThrough.js.map +1 -0
- package/dist/entities/decorators/casts.d.ts +3 -0
- package/dist/entities/decorators/casts.js +38 -0
- package/dist/entities/decorators/casts.js.map +1 -0
- package/dist/entities/decorators/index.d.ts +7 -0
- package/dist/entities/decorators/index.js +24 -0
- package/dist/entities/decorators/index.js.map +1 -0
- package/dist/entities/decorators/metadata.d.ts +19 -0
- package/dist/entities/decorators/metadata.js +12 -0
- package/dist/entities/decorators/metadata.js.map +1 -0
- package/dist/entities/index.d.ts +5 -3
- package/dist/entities/index.js +5 -2
- package/dist/entities/index.js.map +1 -1
- package/dist/entities/relationship.d.ts +1 -6
- package/dist/entities/relationship.js +1 -22
- package/dist/entities/relationship.js.map +1 -1
- package/dist/index.d.ts +1 -9
- package/dist/index.js +1 -14
- package/dist/index.js.map +1 -1
- package/dist/query/DeleteQuery.d.ts +8 -0
- package/dist/query/DeleteQuery.js +17 -0
- package/dist/query/DeleteQuery.js.map +1 -0
- package/dist/query/InsertQuery.d.ts +8 -0
- package/dist/query/InsertQuery.js +17 -0
- package/dist/query/InsertQuery.js.map +1 -0
- package/dist/query/QueryTable.d.ts +7 -0
- package/dist/query/QueryTable.js +3 -0
- package/dist/query/QueryTable.js.map +1 -0
- package/dist/query/SelectQuery.d.ts +9 -0
- package/dist/query/SelectQuery.js +33 -0
- package/dist/query/SelectQuery.js.map +1 -0
- package/dist/query/UpdateQuery.d.ts +8 -0
- package/dist/query/UpdateQuery.js +17 -0
- package/dist/query/UpdateQuery.js.map +1 -0
- package/dist/query/builders/DefaultQueryBuilder.d.ts +87 -0
- package/dist/query/builders/DefaultQueryBuilder.js +524 -0
- package/dist/query/builders/DefaultQueryBuilder.js.map +1 -0
- package/dist/query/builders/QueryBuilder.d.ts +5 -0
- package/dist/query/builders/QueryBuilder.js +7 -0
- package/dist/query/builders/QueryBuilder.js.map +1 -0
- package/dist/query/builders/index.d.ts +2 -2
- package/dist/query/builders/index.js +2 -2
- package/dist/query/builders/index.js.map +1 -1
- package/dist/query/conditions/BasicCondition.d.ts +6 -0
- package/dist/query/conditions/BasicCondition.js +3 -0
- package/dist/query/conditions/BasicCondition.js.map +1 -0
- package/dist/query/conditions/ColumnCondition.d.ts +6 -0
- package/dist/query/conditions/ColumnCondition.js +3 -0
- package/dist/query/conditions/ColumnCondition.js.map +1 -0
- package/dist/query/conditions/Condition.d.ts +5 -0
- package/dist/query/conditions/Condition.js +3 -0
- package/dist/query/conditions/Condition.js.map +1 -0
- package/dist/query/conditions/ConditionConnector.d.ts +4 -0
- package/dist/query/conditions/ConditionConnector.js +9 -0
- package/dist/query/conditions/ConditionConnector.js.map +1 -0
- package/dist/query/conditions/ConditionGroup.d.ts +40 -0
- package/dist/query/conditions/ConditionGroup.js +138 -0
- package/dist/query/conditions/ConditionGroup.js.map +1 -0
- package/dist/query/conditions/ConnectedCondition.d.ts +6 -0
- package/dist/query/conditions/ConnectedCondition.js +3 -0
- package/dist/query/conditions/ConnectedCondition.js.map +1 -0
- package/dist/query/conditions/RawCondition.d.ts +4 -0
- package/dist/query/conditions/RawCondition.js +3 -0
- package/dist/query/conditions/RawCondition.js.map +1 -0
- package/dist/query/conditions/index.d.ts +7 -0
- package/dist/query/conditions/index.js +24 -0
- package/dist/query/conditions/index.js.map +1 -0
- package/dist/query/features/HasAlias.d.ts +6 -0
- package/dist/query/features/HasAlias.js +17 -0
- package/dist/query/features/HasAlias.js.map +1 -0
- package/dist/query/features/HasDistinct.d.ts +6 -0
- package/dist/query/features/HasDistinct.js +20 -0
- package/dist/query/features/HasDistinct.js.map +1 -0
- package/dist/query/features/HasFieldValues.d.ts +9 -0
- package/dist/query/features/HasFieldValues.js +27 -0
- package/dist/query/features/HasFieldValues.js.map +1 -0
- package/dist/query/features/HasGroupByFields.d.ts +7 -0
- package/dist/query/features/HasGroupByFields.js +21 -0
- package/dist/query/features/HasGroupByFields.js.map +1 -0
- package/dist/query/features/HasHavingConditions.d.ts +13 -0
- package/dist/query/features/HasHavingConditions.js +28 -0
- package/dist/query/features/HasHavingConditions.js.map +1 -0
- package/dist/query/features/HasJoins.d.ts +41 -0
- package/dist/query/features/HasJoins.js +66 -0
- package/dist/query/features/HasJoins.js.map +1 -0
- package/dist/query/features/HasLimit.d.ts +6 -0
- package/dist/query/features/HasLimit.js +20 -0
- package/dist/query/features/HasLimit.js.map +1 -0
- package/dist/query/features/HasOffset.d.ts +6 -0
- package/dist/query/features/HasOffset.js +20 -0
- package/dist/query/features/HasOffset.js.map +1 -0
- package/dist/query/features/HasOrderByFields.d.ts +15 -0
- package/dist/query/features/HasOrderByFields.js +38 -0
- package/dist/query/features/HasOrderByFields.js.map +1 -0
- package/dist/query/features/HasSelectFields.d.ts +11 -0
- package/dist/query/features/HasSelectFields.js +21 -0
- package/dist/query/features/HasSelectFields.js.map +1 -0
- package/dist/query/features/HasTable.d.ts +7 -0
- package/dist/query/features/HasTable.js +20 -0
- package/dist/query/features/HasTable.js.map +1 -0
- package/dist/query/features/HasUnions.d.ts +13 -0
- package/dist/query/features/HasUnions.js +21 -0
- package/dist/query/features/HasUnions.js.map +1 -0
- package/dist/query/features/HasWhen.d.ts +3 -0
- package/dist/query/features/HasWhen.js +13 -0
- package/dist/query/features/HasWhen.js.map +1 -0
- package/dist/query/features/HasWhereConditions.d.ts +35 -0
- package/dist/query/features/HasWhereConditions.js +92 -0
- package/dist/query/features/HasWhereConditions.js.map +1 -0
- package/dist/query/features/index.d.ts +14 -14
- package/dist/query/features/index.js +14 -14
- package/dist/query/features/index.js.map +1 -1
- package/dist/query/fields/BasicField.d.ts +5 -0
- package/dist/query/fields/BasicField.js +3 -0
- package/dist/query/fields/BasicField.js.map +1 -0
- package/dist/query/fields/Field.d.ts +3 -0
- package/dist/query/fields/Field.js +3 -0
- package/dist/query/fields/Field.js.map +1 -0
- package/dist/query/fields/RawField.d.ts +1 -0
- package/dist/query/fields/RawField.js +3 -0
- package/dist/query/fields/RawField.js.map +1 -0
- package/dist/query/fields/index.d.ts +3 -0
- package/dist/query/fields/index.js +20 -0
- package/dist/query/fields/index.js.map +1 -0
- package/dist/query/index.d.ts +7 -7
- package/dist/query/index.js +7 -7
- package/dist/query/index.js.map +1 -1
- package/dist/query/query.js +1 -1
- package/dist/query/query.js.map +1 -1
- package/dist/query/statement.js +1 -1
- package/dist/query/statement.js.map +1 -1
- package/dist/utilities.js +2 -3
- package/dist/utilities.js.map +1 -1
- package/package.json +21 -12
package/README.md
CHANGED
|
@@ -702,22 +702,22 @@ try {
|
|
|
702
702
|
|
|
703
703
|
## Entities (Active Record)
|
|
704
704
|
|
|
705
|
-
Entities are Eloquent-style Active Record models that map a
|
|
705
|
+
Entities are Eloquent-style Active Record models that map a class to a database table. Every entity extends the abstract **`BaseEntity`** class and is annotated with TypeScript decorators. `BaseEntity` provides all the static query methods (`find`, `where`, `with`, …) — fully typed — plus the `save()` and `delete()` instance methods.
|
|
706
706
|
|
|
707
707
|
> Enable `"experimentalDecorators": true` and `"useDefineForClassFields": false` in your `tsconfig.json`.
|
|
708
708
|
|
|
709
709
|
### Defining an Entity
|
|
710
710
|
|
|
711
|
-
|
|
711
|
+
Extend `BaseEntity`, annotate the class with `@Entity` and mark its columns with `@Column`. The decorators register the table metadata; `BaseEntity` supplies querying and persistence.
|
|
712
712
|
|
|
713
713
|
```typescript
|
|
714
714
|
import {
|
|
715
|
-
Entity, Column,
|
|
715
|
+
BaseEntity, Entity, Column,
|
|
716
716
|
HasOne, HasMany, BelongsTo, HasOneThrough, HasManyThrough
|
|
717
717
|
} from '@neogroup/neorm'
|
|
718
718
|
|
|
719
719
|
@Entity() // table name defaults to lowercase class name + 's' → 'users'
|
|
720
|
-
class User {
|
|
720
|
+
class User extends BaseEntity {
|
|
721
721
|
@Column({ primaryKey: true, autoGenerated: true })
|
|
722
722
|
id!: number
|
|
723
723
|
|
|
@@ -746,7 +746,7 @@ class User {
|
|
|
746
746
|
}
|
|
747
747
|
|
|
748
748
|
@Entity()
|
|
749
|
-
class Order {
|
|
749
|
+
class Order extends BaseEntity {
|
|
750
750
|
@Column({ primaryKey: true, autoGenerated: true })
|
|
751
751
|
id!: number
|
|
752
752
|
|
|
@@ -765,6 +765,7 @@ class Order {
|
|
|
765
765
|
|
|
766
766
|
| Option | Type | Description |
|
|
767
767
|
|-----------------|------------|-------------|
|
|
768
|
+
| `columnName` | `string` | Database column name. Defaults to the property name. |
|
|
768
769
|
| `cast` | `CastType` | Coerce the value when reading from the DB (see [Casts](#casts)). |
|
|
769
770
|
| `primaryKey` | `boolean` | Marks this column as the primary key. |
|
|
770
771
|
| `autoGenerated` | `boolean` | Column is DB-managed (e.g. `AUTOINCREMENT`). Excluded from INSERT/UPDATE; the generated value is written back to the instance after INSERT. |
|
|
@@ -773,18 +774,20 @@ When a custom table name or primary key column name is needed, pass options to `
|
|
|
773
774
|
|
|
774
775
|
```typescript
|
|
775
776
|
@Entity({ table: 'shipping_addresses' })
|
|
776
|
-
class ShippingAddress {
|
|
777
|
+
class ShippingAddress extends BaseEntity {
|
|
777
778
|
@Column({ primaryKey: true, autoGenerated: true })
|
|
778
779
|
id!: number
|
|
779
780
|
// ...
|
|
780
781
|
}
|
|
781
782
|
```
|
|
782
783
|
|
|
783
|
-
To target a specific data source instead of the active one:
|
|
784
|
+
To target a specific registered data source (by name) instead of the active one:
|
|
784
785
|
|
|
785
786
|
```typescript
|
|
786
|
-
|
|
787
|
-
|
|
787
|
+
DB.register('archive', archiveSource)
|
|
788
|
+
|
|
789
|
+
@Entity({ source: 'archive' }) // the entity operates on DB.source('archive')
|
|
790
|
+
class ArchiveUser extends BaseEntity {
|
|
788
791
|
// ...
|
|
789
792
|
}
|
|
790
793
|
```
|
|
@@ -793,22 +796,20 @@ class ArchiveUser {
|
|
|
793
796
|
|
|
794
797
|
### Querying
|
|
795
798
|
|
|
796
|
-
All `DataTable` query methods are available as static methods
|
|
799
|
+
All `DataTable` query methods are available as static methods inherited from `BaseEntity`, returning a chainable `EntityQuery<T>`. They are fully typed — `User.get()` returns `Promise<User[]>` with no casts needed:
|
|
797
800
|
|
|
798
801
|
```typescript
|
|
799
|
-
const UserModel = User as any // cast needed — TypeScript doesn't see injected statics
|
|
800
|
-
|
|
801
802
|
// Fetch all
|
|
802
|
-
const users = await
|
|
803
|
+
const users = await User.get() // User[]
|
|
803
804
|
|
|
804
805
|
// Find by primary key
|
|
805
|
-
const user = await
|
|
806
|
+
const user = await User.find(1) // User | null
|
|
806
807
|
|
|
807
808
|
// First match
|
|
808
|
-
const admin = await
|
|
809
|
+
const admin = await User.where('role', 'admin').first()
|
|
809
810
|
|
|
810
811
|
// Chained conditions
|
|
811
|
-
const adults = await
|
|
812
|
+
const adults = await User.where('active', 1)
|
|
812
813
|
.whereNotNull('email')
|
|
813
814
|
.orderBy('name')
|
|
814
815
|
.limit(20)
|
|
@@ -821,26 +822,26 @@ The full `where*` / `orWhere*` API, `select()`, `orderBy()`, `limit()`, `offset(
|
|
|
821
822
|
|
|
822
823
|
### Saving & deleting
|
|
823
824
|
|
|
825
|
+
Every entity inherits the `save()` and `delete()` instance methods from `BaseEntity`:
|
|
826
|
+
|
|
824
827
|
```typescript
|
|
825
828
|
// INSERT — autoGenerated PK is written back after insert
|
|
826
|
-
const user = new User()
|
|
827
|
-
user.name
|
|
828
|
-
user.email
|
|
829
|
-
user.age
|
|
830
|
-
user.active =
|
|
831
|
-
await
|
|
829
|
+
const user = new User()
|
|
830
|
+
user.name = 'Alice'
|
|
831
|
+
user.email = 'alice@example.com'
|
|
832
|
+
user.age = 30
|
|
833
|
+
user.active = true
|
|
834
|
+
await user.save()
|
|
832
835
|
console.log(user.id) // populated from lastInsertId
|
|
833
836
|
|
|
834
837
|
// UPDATE — detected by the presence of a primary key value
|
|
835
838
|
user.age = 31
|
|
836
|
-
await
|
|
839
|
+
await user.save()
|
|
837
840
|
|
|
838
|
-
// DELETE
|
|
839
|
-
await
|
|
841
|
+
// DELETE — throws if the primary key is not set
|
|
842
|
+
await user.delete()
|
|
840
843
|
```
|
|
841
844
|
|
|
842
|
-
`Entities.save` and `Entities.delete` read the entity metadata from its constructor at runtime — no coupling between the call site and the `@Entity` definition.
|
|
843
|
-
|
|
844
845
|
---
|
|
845
846
|
|
|
846
847
|
### Casts
|
|
@@ -871,7 +872,7 @@ Use relationship decorators to declare associations between entities:
|
|
|
871
872
|
// HasManyThrough(related, through, foreignKey, throughForeignKey, localKey, throughLocalKey)
|
|
872
873
|
|
|
873
874
|
@Entity({ table: 'countries' })
|
|
874
|
-
class Country {
|
|
875
|
+
class Country extends BaseEntity {
|
|
875
876
|
@Column({ primaryKey: true, autoGenerated: true })
|
|
876
877
|
id!: number
|
|
877
878
|
|
|
@@ -894,22 +895,22 @@ Pass relation names to `with()` to load related entities in a single extra query
|
|
|
894
895
|
|
|
895
896
|
```typescript
|
|
896
897
|
// Preload orders for each user
|
|
897
|
-
const users = await
|
|
898
|
+
const users = await User.with('orders').get()
|
|
898
899
|
users.forEach(u => console.log(u.orders)) // Order[] attached
|
|
899
900
|
|
|
900
901
|
// Multiple relations
|
|
901
|
-
const users = await
|
|
902
|
+
const users = await User.with('orders', 'profile').get()
|
|
902
903
|
|
|
903
904
|
// Dot-notation for nested eager loading
|
|
904
905
|
// Loads orders → users → countries in 3 total queries
|
|
905
|
-
const orders = await
|
|
906
|
+
const orders = await Order.with('user.country').get()
|
|
906
907
|
orders.forEach(o => console.log(o.user.country))
|
|
907
908
|
```
|
|
908
909
|
|
|
909
910
|
`with()` is chainable after any `where*` or ordering method:
|
|
910
911
|
|
|
911
912
|
```typescript
|
|
912
|
-
const users = await
|
|
913
|
+
const users = await User.where('active', 1).with('orders').orderBy('name').get()
|
|
913
914
|
```
|
|
914
915
|
|
|
915
916
|
---
|
|
@@ -920,19 +921,19 @@ Use `joinRelationship` / `innerJoinRelationship` / `leftJoinRelationship` to add
|
|
|
920
921
|
|
|
921
922
|
```typescript
|
|
922
923
|
// INNER JOIN orders ON users.id = orders.userId
|
|
923
|
-
const users = await
|
|
924
|
+
const users = await User.innerJoinRelationship('orders')
|
|
924
925
|
.select('users.*', 'COUNT(orders.id) AS orderCount')
|
|
925
926
|
.groupBy('users.id')
|
|
926
927
|
.get()
|
|
927
928
|
|
|
928
929
|
// LEFT JOIN
|
|
929
|
-
const users = await
|
|
930
|
+
const users = await User.leftJoinRelationship('profile').get()
|
|
930
931
|
```
|
|
931
932
|
|
|
932
933
|
These are available as static methods on every Entity and also on `EntityQuery`:
|
|
933
934
|
|
|
934
935
|
```typescript
|
|
935
|
-
const query =
|
|
936
|
+
const query = User.where('active', 1).leftJoinRelationship('profile')
|
|
936
937
|
```
|
|
937
938
|
|
|
938
939
|
---
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DataSet } from './DataSet';
|
|
2
|
+
export interface Connection {
|
|
3
|
+
query(sql: string, bindings?: Array<any>): Promise<Array<DataSet>>;
|
|
4
|
+
execute(sql: string, bindings?: Array<any>): Promise<number>;
|
|
5
|
+
lastInsertId(): Promise<number>;
|
|
6
|
+
beginTransaction(): Promise<void>;
|
|
7
|
+
rollbackTransaction(): Promise<void>;
|
|
8
|
+
commitTransaction(): Promise<void>;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Connection.js","sourceRoot":"","sources":["../../src/database/Connection.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { DataConnection } from './DataConnection';
|
|
2
|
+
import { DataSet } from './DataSet';
|
|
3
|
+
import { DataSource } from './DataSource';
|
|
4
|
+
import { DataTable } from './DataTable';
|
|
5
|
+
import { ConditionGroup, DeleteQuery, InsertQuery, Query, QueryTable, SelectQuery, UpdateQuery } from './query';
|
|
6
|
+
export declare abstract class DB {
|
|
7
|
+
private static get _sources();
|
|
8
|
+
private static get _activeSourceName();
|
|
9
|
+
private static set _activeSourceName(value);
|
|
10
|
+
static register(source: DataSource): void;
|
|
11
|
+
static register(sourceName: string, source: DataSource): void;
|
|
12
|
+
static setActiveSource(sourceName: string): void;
|
|
13
|
+
static source(sourceName: string): DataSource;
|
|
14
|
+
/**
|
|
15
|
+
* Reads environment variables and registers the corresponding data sources.
|
|
16
|
+
* Called automatically the first time a source is needed if none have been
|
|
17
|
+
* registered manually.
|
|
18
|
+
*
|
|
19
|
+
* Supported variables:
|
|
20
|
+
*
|
|
21
|
+
* Default source:
|
|
22
|
+
* DB_DRIVER sqlite | postgres | mysql (required)
|
|
23
|
+
* DB_FILE path to SQLite file (sqlite only, default: :memory:)
|
|
24
|
+
* DB_HOST database host (postgres / mysql)
|
|
25
|
+
* DB_PORT database port (postgres / mysql)
|
|
26
|
+
* DB_NAME database name (postgres / mysql)
|
|
27
|
+
* DB_USERNAME login username (postgres / mysql)
|
|
28
|
+
* DB_PASSWORD login password (postgres / mysql)
|
|
29
|
+
* DB_DEBUG enable debug mode (true/false, 1/0, yes/no, on/off)
|
|
30
|
+
* DB_READONLY readonly mode (true/false, 1/0, yes/no, on/off)
|
|
31
|
+
*
|
|
32
|
+
* Named source (replace <NAME> with the desired source name in upper-case):
|
|
33
|
+
* DB_<NAME>_DRIVER, DB_<NAME>_HOST, DB_<NAME>_PORT, DB_<NAME>_NAME,
|
|
34
|
+
* DB_<NAME>_USERNAME, DB_<NAME>_PASSWORD, DB_<NAME>_FILE,
|
|
35
|
+
* DB_<NAME>_DEBUG, DB_<NAME>_READONLY
|
|
36
|
+
*
|
|
37
|
+
* Example:
|
|
38
|
+
* DB_DRIVER=postgres DB_HOST=localhost DB_NAME=app DB_USERNAME=user DB_PASSWORD=pass
|
|
39
|
+
* DB_REPORTING_DRIVER=sqlite DB_REPORTING_FILE=./reporting.db
|
|
40
|
+
*/
|
|
41
|
+
private static configure;
|
|
42
|
+
private static _buildSourceFromEnv;
|
|
43
|
+
private static _parseEnvBoolean;
|
|
44
|
+
private static _buildDriverSource;
|
|
45
|
+
private static _ensureConfigured;
|
|
46
|
+
static table(tableName: string): DataTable;
|
|
47
|
+
static conditionGroup(): ConditionGroup;
|
|
48
|
+
static selectQuery(table?: QueryTable): SelectQuery;
|
|
49
|
+
static updateQuery(table?: QueryTable): UpdateQuery;
|
|
50
|
+
static deleteQuery(table?: QueryTable): DeleteQuery;
|
|
51
|
+
static insertQuery(table?: QueryTable): InsertQuery;
|
|
52
|
+
static connection(): Promise<DataConnection>;
|
|
53
|
+
static query(sql: string, bindings?: Array<any>): Promise<Array<DataSet>>;
|
|
54
|
+
static query(query: Query): Promise<Array<DataSet>>;
|
|
55
|
+
static execute(sql: string, bindings?: Array<any>): Promise<number>;
|
|
56
|
+
static execute(query: Query): Promise<number>;
|
|
57
|
+
static beginTransaction(): Promise<void>;
|
|
58
|
+
static commitTransaction(): Promise<void>;
|
|
59
|
+
static rollbackTransaction(): Promise<void>;
|
|
60
|
+
static executeTransaction(callback: (connection: DataConnection) => Promise<void>): Promise<void>;
|
|
61
|
+
static getActiveSource(): DataSource;
|
|
62
|
+
private static get _activeSource();
|
|
63
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DB = void 0;
|
|
4
|
+
const query_1 = require("./query");
|
|
5
|
+
function getGlobalState() {
|
|
6
|
+
const g = globalThis;
|
|
7
|
+
if (!g.__neorm) {
|
|
8
|
+
g.__neorm = { sources: new Map() };
|
|
9
|
+
}
|
|
10
|
+
return g.__neorm;
|
|
11
|
+
}
|
|
12
|
+
// ── DB ────────────────────────────────────────────────────────────────────────
|
|
13
|
+
class DB {
|
|
14
|
+
static get _sources() {
|
|
15
|
+
return getGlobalState().sources;
|
|
16
|
+
}
|
|
17
|
+
static get _activeSourceName() {
|
|
18
|
+
return getGlobalState().activeSourceName;
|
|
19
|
+
}
|
|
20
|
+
static set _activeSourceName(value) {
|
|
21
|
+
getGlobalState().activeSourceName = value;
|
|
22
|
+
}
|
|
23
|
+
static register(sourceOrName, source) {
|
|
24
|
+
const sourceName = source ? sourceOrName : 'source' + (this._sources.size + 1);
|
|
25
|
+
const sourceToRegister = source !== null && source !== void 0 ? source : sourceOrName;
|
|
26
|
+
this._sources.set(sourceName, sourceToRegister);
|
|
27
|
+
if (!this._activeSourceName) {
|
|
28
|
+
this._activeSourceName = sourceName;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
static setActiveSource(sourceName) {
|
|
32
|
+
if (!this._sources.has(sourceName)) {
|
|
33
|
+
throw new Error(`No DataSource registered with the name "${sourceName}"`);
|
|
34
|
+
}
|
|
35
|
+
this._activeSourceName = sourceName;
|
|
36
|
+
}
|
|
37
|
+
static source(sourceName) {
|
|
38
|
+
this._ensureConfigured();
|
|
39
|
+
const source = this._sources.get(sourceName);
|
|
40
|
+
if (!source) {
|
|
41
|
+
throw new Error(`No DataSource registered with the name "${sourceName}"`);
|
|
42
|
+
}
|
|
43
|
+
return source;
|
|
44
|
+
}
|
|
45
|
+
// ── Environment-variable configuration ──────────────────────────────────────
|
|
46
|
+
/**
|
|
47
|
+
* Reads environment variables and registers the corresponding data sources.
|
|
48
|
+
* Called automatically the first time a source is needed if none have been
|
|
49
|
+
* registered manually.
|
|
50
|
+
*
|
|
51
|
+
* Supported variables:
|
|
52
|
+
*
|
|
53
|
+
* Default source:
|
|
54
|
+
* DB_DRIVER sqlite | postgres | mysql (required)
|
|
55
|
+
* DB_FILE path to SQLite file (sqlite only, default: :memory:)
|
|
56
|
+
* DB_HOST database host (postgres / mysql)
|
|
57
|
+
* DB_PORT database port (postgres / mysql)
|
|
58
|
+
* DB_NAME database name (postgres / mysql)
|
|
59
|
+
* DB_USERNAME login username (postgres / mysql)
|
|
60
|
+
* DB_PASSWORD login password (postgres / mysql)
|
|
61
|
+
* DB_DEBUG enable debug mode (true/false, 1/0, yes/no, on/off)
|
|
62
|
+
* DB_READONLY readonly mode (true/false, 1/0, yes/no, on/off)
|
|
63
|
+
*
|
|
64
|
+
* Named source (replace <NAME> with the desired source name in upper-case):
|
|
65
|
+
* DB_<NAME>_DRIVER, DB_<NAME>_HOST, DB_<NAME>_PORT, DB_<NAME>_NAME,
|
|
66
|
+
* DB_<NAME>_USERNAME, DB_<NAME>_PASSWORD, DB_<NAME>_FILE,
|
|
67
|
+
* DB_<NAME>_DEBUG, DB_<NAME>_READONLY
|
|
68
|
+
*
|
|
69
|
+
* Example:
|
|
70
|
+
* DB_DRIVER=postgres DB_HOST=localhost DB_NAME=app DB_USERNAME=user DB_PASSWORD=pass
|
|
71
|
+
* DB_REPORTING_DRIVER=sqlite DB_REPORTING_FILE=./reporting.db
|
|
72
|
+
*/
|
|
73
|
+
static configure() {
|
|
74
|
+
if (this._sources.size > 0) {
|
|
75
|
+
return; // already configured — manual register() takes precedence
|
|
76
|
+
}
|
|
77
|
+
const env = process.env;
|
|
78
|
+
// 1. Default (unnamed) source — registered first so it becomes active
|
|
79
|
+
const defaultDriver = env['DB_DRIVER'];
|
|
80
|
+
if (defaultDriver) {
|
|
81
|
+
const get = (key) => env[`DB_${key}`];
|
|
82
|
+
this.register(this._buildSourceFromEnv(defaultDriver, get));
|
|
83
|
+
}
|
|
84
|
+
// 2. Named sources — DB_<NAME>_DRIVER pattern
|
|
85
|
+
for (const key of Object.keys(env).sort()) {
|
|
86
|
+
const match = key.match(/^DB_([A-Z][A-Z0-9_]*)_DRIVER$/);
|
|
87
|
+
if (!match) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const name = match[1].toLowerCase();
|
|
91
|
+
const prefix = `DB_${match[1]}_`;
|
|
92
|
+
const get = (k) => env[prefix + k];
|
|
93
|
+
this.register(name, this._buildSourceFromEnv(env[key], get));
|
|
94
|
+
}
|
|
95
|
+
if (this._sources.size === 0) {
|
|
96
|
+
throw new Error('No data source configured. ' +
|
|
97
|
+
'Call DB.register() or set the DB_DRIVER environment variable ' +
|
|
98
|
+
'(e.g. DB_DRIVER=sqlite, DB_DRIVER=postgres, DB_DRIVER=mysql).');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
static _buildSourceFromEnv(driver, get) {
|
|
102
|
+
const source = this._buildDriverSource(driver, get);
|
|
103
|
+
const debug = get('DEBUG');
|
|
104
|
+
const readonly = get('READONLY');
|
|
105
|
+
if (debug !== undefined) {
|
|
106
|
+
source.setDebugEnabled(this._parseEnvBoolean(debug));
|
|
107
|
+
}
|
|
108
|
+
if (readonly !== undefined) {
|
|
109
|
+
source.setReadonly(this._parseEnvBoolean(readonly));
|
|
110
|
+
}
|
|
111
|
+
return source;
|
|
112
|
+
}
|
|
113
|
+
static _parseEnvBoolean(value) {
|
|
114
|
+
return ['true', '1', 'yes', 'on'].includes(value.trim().toLowerCase());
|
|
115
|
+
}
|
|
116
|
+
static _buildDriverSource(driver, get) {
|
|
117
|
+
var _a, _b, _c, _d, _e, _f;
|
|
118
|
+
switch (driver.toLowerCase()) {
|
|
119
|
+
case 'sqlite': {
|
|
120
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
121
|
+
const { SqliteDataSource } = require('./sources/sqlite');
|
|
122
|
+
const s = new SqliteDataSource();
|
|
123
|
+
const file = get('FILE');
|
|
124
|
+
if (file) {
|
|
125
|
+
s.setFilename(file);
|
|
126
|
+
}
|
|
127
|
+
return s;
|
|
128
|
+
}
|
|
129
|
+
case 'postgres':
|
|
130
|
+
case 'postgresql': {
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
132
|
+
const { PostgresDataSource } = require('./sources/postgres');
|
|
133
|
+
const s = new PostgresDataSource();
|
|
134
|
+
const host = get('HOST');
|
|
135
|
+
const port = get('PORT');
|
|
136
|
+
const name = (_a = get('NAME')) !== null && _a !== void 0 ? _a : get('DATABASE');
|
|
137
|
+
const username = (_b = get('USERNAME')) !== null && _b !== void 0 ? _b : get('USER');
|
|
138
|
+
const password = (_c = get('PASSWORD')) !== null && _c !== void 0 ? _c : get('PASS');
|
|
139
|
+
if (host) {
|
|
140
|
+
s.setHost(host);
|
|
141
|
+
}
|
|
142
|
+
if (port) {
|
|
143
|
+
s.setPort(Number(port));
|
|
144
|
+
}
|
|
145
|
+
if (name) {
|
|
146
|
+
s.setDatabaseName(name);
|
|
147
|
+
}
|
|
148
|
+
if (username) {
|
|
149
|
+
s.setUsername(username);
|
|
150
|
+
}
|
|
151
|
+
if (password) {
|
|
152
|
+
s.setPassword(password);
|
|
153
|
+
}
|
|
154
|
+
return s;
|
|
155
|
+
}
|
|
156
|
+
case 'mysql': {
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
158
|
+
const { MysqlDataSource } = require('./sources/mysql');
|
|
159
|
+
const s = new MysqlDataSource();
|
|
160
|
+
const host = get('HOST');
|
|
161
|
+
const port = get('PORT');
|
|
162
|
+
const name = (_d = get('NAME')) !== null && _d !== void 0 ? _d : get('DATABASE');
|
|
163
|
+
const username = (_e = get('USERNAME')) !== null && _e !== void 0 ? _e : get('USER');
|
|
164
|
+
const password = (_f = get('PASSWORD')) !== null && _f !== void 0 ? _f : get('PASS');
|
|
165
|
+
if (host) {
|
|
166
|
+
s.setHost(host);
|
|
167
|
+
}
|
|
168
|
+
if (port) {
|
|
169
|
+
s.setPort(Number(port));
|
|
170
|
+
}
|
|
171
|
+
if (name) {
|
|
172
|
+
s.setDatabaseName(name);
|
|
173
|
+
}
|
|
174
|
+
if (username) {
|
|
175
|
+
s.setUsername(username);
|
|
176
|
+
}
|
|
177
|
+
if (password) {
|
|
178
|
+
s.setPassword(password);
|
|
179
|
+
}
|
|
180
|
+
return s;
|
|
181
|
+
}
|
|
182
|
+
default:
|
|
183
|
+
throw new Error(`Unknown DB driver "${driver}". Supported drivers: sqlite, postgres, mysql.`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
static _ensureConfigured() {
|
|
187
|
+
if (this._sources.size === 0) {
|
|
188
|
+
this.configure();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// ── Query builder helpers ────────────────────────────────────────────────────
|
|
192
|
+
static table(tableName) {
|
|
193
|
+
return this._activeSource.table(tableName);
|
|
194
|
+
}
|
|
195
|
+
static conditionGroup() {
|
|
196
|
+
return new query_1.ConditionGroup();
|
|
197
|
+
}
|
|
198
|
+
static selectQuery(table) {
|
|
199
|
+
return new query_1.SelectQuery(table);
|
|
200
|
+
}
|
|
201
|
+
static updateQuery(table) {
|
|
202
|
+
return new query_1.UpdateQuery(table);
|
|
203
|
+
}
|
|
204
|
+
static deleteQuery(table) {
|
|
205
|
+
return new query_1.DeleteQuery(table);
|
|
206
|
+
}
|
|
207
|
+
static insertQuery(table) {
|
|
208
|
+
return new query_1.InsertQuery(table);
|
|
209
|
+
}
|
|
210
|
+
// ── Connection ──────────────────────────────────────────────────────────────
|
|
211
|
+
static connection() {
|
|
212
|
+
return this._activeSource.getConnection();
|
|
213
|
+
}
|
|
214
|
+
static async query() {
|
|
215
|
+
const conn = await this.connection();
|
|
216
|
+
// @ts-ignore
|
|
217
|
+
return conn.query(...arguments);
|
|
218
|
+
}
|
|
219
|
+
static async execute() {
|
|
220
|
+
const conn = await this.connection();
|
|
221
|
+
// @ts-ignore
|
|
222
|
+
return conn.execute(...arguments);
|
|
223
|
+
}
|
|
224
|
+
// ── Transactions ────────────────────────────────────────────────────────────
|
|
225
|
+
static async beginTransaction() {
|
|
226
|
+
return (await this.connection()).beginTransaction();
|
|
227
|
+
}
|
|
228
|
+
static async commitTransaction() {
|
|
229
|
+
return (await this.connection()).commitTransaction();
|
|
230
|
+
}
|
|
231
|
+
static async rollbackTransaction() {
|
|
232
|
+
return (await this.connection()).rollbackTransaction();
|
|
233
|
+
}
|
|
234
|
+
static async executeTransaction(callback) {
|
|
235
|
+
return (await this.connection()).executeTransaction(callback);
|
|
236
|
+
}
|
|
237
|
+
// ── Private helpers ─────────────────────────────────────────────────────────
|
|
238
|
+
static getActiveSource() {
|
|
239
|
+
return this._activeSource;
|
|
240
|
+
}
|
|
241
|
+
static get _activeSource() {
|
|
242
|
+
this._ensureConfigured();
|
|
243
|
+
return this._sources.get(this._activeSourceName);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
exports.DB = DB;
|
|
247
|
+
//# sourceMappingURL=DB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DB.js","sourceRoot":"","sources":["../../src/database/DB.ts"],"names":[],"mappings":";;;AAIA,mCAA+G;AAS/G,SAAS,cAAc;IACrB,MAAM,CAAC,GAAG,UAAiB,CAAA;IAE3B,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACf,CAAC,CAAC,OAAO,GAAG,EAAE,OAAO,EAAE,IAAI,GAAG,EAAsB,EAAE,CAAA;IACxD,CAAC;IAED,OAAO,CAAC,CAAC,OAAkB,CAAA;AAC7B,CAAC;AAED,iFAAiF;AAEjF,MAAsB,EAAE;IACd,MAAM,KAAK,QAAQ;QACzB,OAAO,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UAAU,EAAE,CAAC,CAAC,gBAAgB,EAAE,CAAA;IACrD,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,iBAAiB;QACnC,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,iBAAiB,EAAE,CAAA;IACtD,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,mBAAmB;QACrC,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,mBAAmB,EAAE,CAAA;IACxD,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAuD;QAC5F,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;IAC/D,CAAC;IAED,+EAA+E;IAExE,MAAM,CAAC,eAAe;QAC3B,OAAO,IAAI,CAAC,aAAa,CAAA;IAC3B,CAAC;IAEO,MAAM,KAAK,aAAa;QAC9B,IAAI,CAAC,iBAAiB,EAAE,CAAA;QAExB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAkB,CAAe,CAAA;IACjE,CAAC;CACF;AAvTD,gBAuTC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Connection } from './Connection';
|
|
2
|
+
import { DataSet } from './DataSet';
|
|
3
|
+
import { Query, QueryBuilder } from './query';
|
|
4
|
+
export declare class DataConnection {
|
|
5
|
+
private connection;
|
|
6
|
+
private queryBuilder;
|
|
7
|
+
private debug;
|
|
8
|
+
private readonly;
|
|
9
|
+
constructor(connection: Connection, queryBuilder: QueryBuilder);
|
|
10
|
+
setDebugEnabled(debug: boolean): void;
|
|
11
|
+
isDebugEnabled(): boolean;
|
|
12
|
+
setReadonly(readonly: boolean): void;
|
|
13
|
+
isReadonly(): boolean;
|
|
14
|
+
beginTransaction(): Promise<void>;
|
|
15
|
+
rollbackTransaction(): Promise<void>;
|
|
16
|
+
commitTransaction(): Promise<void>;
|
|
17
|
+
lastInsertId(): Promise<number>;
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
query(sql: string, bindings?: Array<any>): Promise<Array<DataSet>>;
|
|
20
|
+
query(query: Query): Promise<Array<DataSet>>;
|
|
21
|
+
execute(sql: string, bindings?: Array<any>): Promise<number>;
|
|
22
|
+
execute(query: Query): Promise<number>;
|
|
23
|
+
executeTransaction(transaction: (connection: DataConnection) => Promise<void>): Promise<void>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataConnection = void 0;
|
|
4
|
+
const utilities_1 = require("../utilities");
|
|
5
|
+
const query_1 = require("./query");
|
|
6
|
+
class DataConnection {
|
|
7
|
+
constructor(connection, queryBuilder) {
|
|
8
|
+
this.debug = false;
|
|
9
|
+
this.readonly = false;
|
|
10
|
+
this.connection = connection;
|
|
11
|
+
this.queryBuilder = queryBuilder;
|
|
12
|
+
}
|
|
13
|
+
setDebugEnabled(debug) {
|
|
14
|
+
this.debug = debug;
|
|
15
|
+
}
|
|
16
|
+
isDebugEnabled() {
|
|
17
|
+
return this.debug;
|
|
18
|
+
}
|
|
19
|
+
setReadonly(readonly) {
|
|
20
|
+
this.readonly = readonly;
|
|
21
|
+
}
|
|
22
|
+
isReadonly() {
|
|
23
|
+
return this.readonly;
|
|
24
|
+
}
|
|
25
|
+
async beginTransaction() {
|
|
26
|
+
if (this.debug) {
|
|
27
|
+
(0, utilities_1.debugLog)('[BEGIN TRANSACTION]');
|
|
28
|
+
}
|
|
29
|
+
if (!this.readonly) {
|
|
30
|
+
await this.connection.beginTransaction();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async rollbackTransaction() {
|
|
34
|
+
if (this.debug) {
|
|
35
|
+
(0, utilities_1.debugLog)('[ROLLBACK TRANSACTION]');
|
|
36
|
+
}
|
|
37
|
+
if (!this.readonly) {
|
|
38
|
+
await this.connection.rollbackTransaction();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async commitTransaction() {
|
|
42
|
+
if (this.debug) {
|
|
43
|
+
(0, utilities_1.debugLog)('[COMMIT TRANSACTION]');
|
|
44
|
+
}
|
|
45
|
+
if (!this.readonly) {
|
|
46
|
+
await this.connection.commitTransaction();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async lastInsertId() {
|
|
50
|
+
return this.connection.lastInsertId();
|
|
51
|
+
}
|
|
52
|
+
async close() {
|
|
53
|
+
await this.connection.close();
|
|
54
|
+
}
|
|
55
|
+
async query(sqlOrQuery, bindings) {
|
|
56
|
+
if (sqlOrQuery instanceof query_1.Query) {
|
|
57
|
+
const statement = this.queryBuilder.buildQuery(sqlOrQuery);
|
|
58
|
+
sqlOrQuery = statement.sql;
|
|
59
|
+
bindings = statement.bindings;
|
|
60
|
+
}
|
|
61
|
+
if (this.debug) {
|
|
62
|
+
(0, utilities_1.debugLog)('SQL: ' +
|
|
63
|
+
sqlOrQuery +
|
|
64
|
+
';' +
|
|
65
|
+
(bindings
|
|
66
|
+
? ' [' + bindings.map((value) => (typeof value === 'string' ? '"' + value + '"' : value)).join(', ') + ']'
|
|
67
|
+
: ''));
|
|
68
|
+
}
|
|
69
|
+
return await this.connection.query(sqlOrQuery, bindings);
|
|
70
|
+
}
|
|
71
|
+
async execute(sqlOrQuery, bindings) {
|
|
72
|
+
if (sqlOrQuery instanceof query_1.Query) {
|
|
73
|
+
const statement = this.queryBuilder.buildQuery(sqlOrQuery);
|
|
74
|
+
sqlOrQuery = statement.sql;
|
|
75
|
+
bindings = statement.bindings;
|
|
76
|
+
}
|
|
77
|
+
if (this.debug) {
|
|
78
|
+
(0, utilities_1.debugLog)('SQL: ' +
|
|
79
|
+
sqlOrQuery +
|
|
80
|
+
';' +
|
|
81
|
+
(bindings
|
|
82
|
+
? ' [' + bindings.map((value) => (typeof value === 'string' ? '"' + value + '"' : value)).join(', ') + ']'
|
|
83
|
+
: ''));
|
|
84
|
+
}
|
|
85
|
+
return this.readonly ? 0 : await this.connection.execute(sqlOrQuery, bindings);
|
|
86
|
+
}
|
|
87
|
+
async executeTransaction(transaction) {
|
|
88
|
+
await this.beginTransaction();
|
|
89
|
+
try {
|
|
90
|
+
await transaction(this);
|
|
91
|
+
await this.commitTransaction();
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
await this.rollbackTransaction();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.DataConnection = DataConnection;
|
|
99
|
+
//# sourceMappingURL=DataConnection.js.map
|