@stacksjs/orm 0.68.1 → 0.69.2

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.
@@ -0,0 +1 @@
1
+ export declare type * from '../../../types/requests.d.ts'
@@ -0,0 +1,96 @@
1
+ declare interface WhereCondition {
2
+ type: 'and' | 'or'
3
+ method: 'where' | 'whereIn' | 'whereNull' | 'whereNotNull' | 'whereBetween' | 'whereExists'
4
+ column: string
5
+ operator?: string
6
+ value?: any
7
+ values?: any[]
8
+ callback?: (query: SubqueryBuilder) => void
9
+ }
10
+ export declare class SubqueryBuilder {
11
+ private conditions: WhereCondition[] = []
12
+
13
+ where(...args: (string | number | boolean | undefined | null)[]): void {
14
+ this.addCondition('and', 'where', ...args)
15
+ }
16
+
17
+ orWhere(...args: (string | number | boolean | undefined | null)[]): void {
18
+ this.addCondition('or', 'where', ...args)
19
+ }
20
+
21
+ whereIn(column: string, values: any[]): void {
22
+ this.conditions.push({
23
+ type: 'and',
24
+ method: 'whereIn',
25
+ column,
26
+ values,
27
+ })
28
+ }
29
+
30
+ whereNotIn(column: string, values: any[]): void {
31
+ this.conditions.push({
32
+ type: 'and',
33
+ method: 'whereIn',
34
+ column,
35
+ values,
36
+ operator: 'not',
37
+ })
38
+ }
39
+
40
+ whereNull(column: string): void {
41
+ this.conditions.push({
42
+ type: 'and',
43
+ method: 'whereNull',
44
+ column,
45
+ })
46
+ }
47
+
48
+ whereNotNull(column: string): void {
49
+ this.conditions.push({
50
+ type: 'and',
51
+ method: 'whereNotNull',
52
+ column,
53
+ })
54
+ }
55
+
56
+ whereBetween(column: string, range: [any, any]): void {
57
+ this.conditions.push({
58
+ type: 'and',
59
+ method: 'whereBetween',
60
+ column,
61
+ values: range,
62
+ })
63
+ }
64
+
65
+ whereExists(callback: (query: SubqueryBuilder) => void): void {
66
+ this.conditions.push({
67
+ type: 'and',
68
+ method: 'whereExists',
69
+ column: '',
70
+ callback,
71
+ })
72
+ }
73
+
74
+ private addCondition(type: 'and' | 'or', method: 'where', ...args: (string | number | boolean | undefined | null)[]): void {
75
+ let column: any
76
+ let operator: any
77
+ let value: any
78
+
79
+ if (args.length === 2) {
80
+ [column, value] = args
81
+ operator = '='
82
+ }
83
+ else if (args.length === 3) {
84
+ [column, operator, value] = args
85
+ }
86
+ else {
87
+ throw new HttpError(500, 'Invalid number of arguments')
88
+ }
89
+
90
+ this.conditions.push({ type, method, column, operator, value })
91
+ }
92
+
93
+ getConditions(): WhereCondition[] {
94
+ return this.conditions
95
+ }
96
+ }
@@ -0,0 +1 @@
1
+ export declare function transactionBuilder(callback: ()): Promise<void>;
package/dist/utils.d.ts CHANGED
@@ -1,19 +1,20 @@
1
1
  declare type ModelPath = string
2
- export declare function modelTableName(model: Model | ModelPath): Promise<string>;
2
+
3
+ export async function modelTableName(model: Model | ModelPath): Promise<string> {
4
+ if (typeof model === 'string') {
5
+ model = (await import(model)).default as Model
6
+ }
7
+
8
+ return model.table ?? snakeCase(plural(model?.name || ''))
9
+ }
3
10
  export declare function getModelName(model: Model, modelPath: string): string;
4
11
  export declare function getTableName(model: Model, modelPath: string): string;
5
12
  export declare function getPivotTableName(formattedModelName: string, modelRelationTable: string): string;
6
13
  export declare function hasRelations(obj: any, key: string): boolean;
7
- export declare function getRelations(model: Model, modelName: string): Promise<RelationConfig[]>;
8
14
  export declare function getRelationType(relation: string): string;
9
15
  export declare function getRelationCount(relation: string): string;
10
- export declare function getPivotTables(model: Model, modelPath: string,): Promise<{ table: string, firstForeignKey?: string, secondForeignKey?: string }[]>;
11
- export declare function fetchOtherModelRelations(modelName?: string): Promise<RelationConfig[]>;
12
- export declare function getHiddenAttributes(attributes: Attributes | undefined): string[];
13
- export declare function getFillableAttributes(attributes: Attributes | undefined, otherModelRelations: RelationConfig[]): string[];
14
- export declare function writeModelNames(): Promise<void>;
16
+ export declare function getHiddenAttributes(attributes: AttributesElements | undefined): string[];
17
+ export declare function getGuardedAttributes(model: Model): string[];
18
+ export declare function getFillableAttributes(model: Model, otherModelRelations: RelationConfig[]): string[];
15
19
  declare function parseRule(rule: string): FieldArrayElement | null;
16
- export declare function generateModelString(tableName: string, modelName: string, model: Model, attributes: ModelElement[],): Promise<string>;
17
- export declare function generateModelFiles(modelStringFile?: string): Promise<void>;
18
- export declare function extractAttributesFromModel(filePath: string): Promise<Attributes>;
19
- declare function ensureCodeStyle(): Promise<void>;
20
+ export declare function mapEntity(attribute: ModelElement): string | undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/orm",
3
3
  "type": "module",
4
- "version": "0.68.1",
4
+ "version": "0.69.2",
5
5
  "description": "The Stacks ORM integration",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": ["Chris Breuer <chris@stacksjs.org>"],
@@ -33,13 +33,11 @@
33
33
  "typecheck": "bun tsc --noEmit",
34
34
  "prepublishOnly": "bun run build"
35
35
  },
36
- "dependencies": {
37
- "@stacksjs/build": "0.67.0",
38
- "@stacksjs/config": "0.67.0",
39
- "@stacksjs/query-builder": "0.67.0",
40
- "@stacksjs/types": "0.67.0"
41
- },
42
36
  "devDependencies": {
43
- "@stacksjs/development": "0.67.0"
37
+ "@stacksjs/build": "0.69.2",
38
+ "@stacksjs/config": "0.69.2",
39
+ "@stacksjs/development": "0.69.2",
40
+ "@stacksjs/query-builder": "0.69.2",
41
+ "@stacksjs/types": "0.69.2"
44
42
  }
45
43
  }
Binary file