@bunnykit/orm 0.1.4 → 0.1.6
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 +420 -81
- package/dist/bin/bunny.js +133 -19
- package/dist/src/config/BunnyConfig.d.ts +28 -0
- package/dist/src/config/BunnyConfig.js +14 -0
- package/dist/src/connection/Connection.d.ts +20 -1
- package/dist/src/connection/Connection.js +80 -2
- package/dist/src/connection/ConnectionManager.d.ts +40 -0
- package/dist/src/connection/ConnectionManager.js +104 -0
- package/dist/src/connection/TenantContext.d.ts +15 -0
- package/dist/src/connection/TenantContext.js +22 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +4 -0
- package/dist/src/model/BelongsToMany.js +9 -6
- package/dist/src/model/Model.d.ts +41 -0
- package/dist/src/model/Model.js +217 -18
- package/dist/src/model/ModelNotFoundError.d.ts +5 -0
- package/dist/src/model/ModelNotFoundError.js +13 -0
- package/dist/src/model/MorphRelations.js +10 -10
- package/dist/src/query/Builder.d.ts +85 -7
- package/dist/src/query/Builder.js +489 -68
- package/dist/src/query/grammars/Grammar.d.ts +19 -0
- package/dist/src/query/grammars/Grammar.js +47 -0
- package/dist/src/query/grammars/MySqlGrammar.d.ts +13 -0
- package/dist/src/query/grammars/MySqlGrammar.js +59 -0
- package/dist/src/query/grammars/PostgresGrammar.d.ts +13 -0
- package/dist/src/query/grammars/PostgresGrammar.js +62 -0
- package/dist/src/query/grammars/SQLiteGrammar.d.ts +14 -0
- package/dist/src/query/grammars/SQLiteGrammar.js +63 -0
- package/dist/src/schema/Schema.js +44 -26
- package/dist/src/typegen/TypeGenerator.js +4 -2
- package/dist/src/types/index.d.ts +10 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Connection } from "../connection/Connection.js";
|
|
2
|
-
import type { WhereClause, OrderClause } from "../types/index.js";
|
|
2
|
+
import type { WhereClause, OrderClause, HavingClause, UnionClause } from "../types/index.js";
|
|
3
3
|
import type { Model } from "../model/Model.js";
|
|
4
4
|
type RelationConstraint = (query: Builder<any>) => void | Builder<any>;
|
|
5
5
|
export interface Paginator<T> {
|
|
@@ -18,44 +18,95 @@ export declare class Builder<T = Record<string, any>> {
|
|
|
18
18
|
wheres: WhereClause[];
|
|
19
19
|
orders: OrderClause[];
|
|
20
20
|
groups: string[];
|
|
21
|
-
havings:
|
|
21
|
+
havings: HavingClause[];
|
|
22
22
|
limitValue?: number;
|
|
23
23
|
offsetValue?: number;
|
|
24
24
|
joins: string[];
|
|
25
25
|
distinctFlag: boolean;
|
|
26
26
|
model?: typeof Model;
|
|
27
27
|
eagerLoads: string[];
|
|
28
|
+
randomOrderFlag: boolean;
|
|
29
|
+
lockMode?: string;
|
|
30
|
+
unions: UnionClause[];
|
|
31
|
+
fromRaw?: string;
|
|
32
|
+
updateJoins: string[];
|
|
28
33
|
constructor(connection: Connection, table: string);
|
|
34
|
+
private get grammar();
|
|
29
35
|
setModel(model: typeof Model): this;
|
|
30
36
|
table(table: string): this;
|
|
31
37
|
select(...columns: string[]): this;
|
|
32
38
|
distinct(): this;
|
|
33
|
-
where(column: string | Record<string, any
|
|
34
|
-
|
|
39
|
+
where(column: string | Record<string, any> | ((query: Builder<T>) => void), operator?: string | any, value?: any, boolean?: "and" | "or", scope?: string): this;
|
|
40
|
+
private whereNested;
|
|
41
|
+
orWhere(column: string | Record<string, any> | ((query: Builder<T>) => void), operator?: string | any, value?: any): this;
|
|
42
|
+
whereNot(column: string | Record<string, any>, value?: any, boolean?: "and" | "or"): this;
|
|
43
|
+
orWhereNot(column: string | Record<string, any>, value?: any): this;
|
|
35
44
|
whereIn(column: string, values: any[], boolean?: "and" | "or", scope?: string): this;
|
|
36
45
|
whereNotIn(column: string, values: any[], boolean?: "and" | "or", scope?: string): this;
|
|
37
46
|
whereNull(column: string, boolean?: "and" | "or", scope?: string): this;
|
|
38
47
|
whereNotNull(column: string, boolean?: "and" | "or", scope?: string): this;
|
|
39
48
|
whereBetween(column: string, values: [any, any], boolean?: "and" | "or", scope?: string): this;
|
|
40
49
|
whereNotBetween(column: string, values: [any, any], boolean?: "and" | "or", scope?: string): this;
|
|
50
|
+
whereDate(column: string, operator?: string | any, value?: any, boolean?: "and" | "or"): this;
|
|
51
|
+
orWhereDate(column: string, operator?: string | any, value?: any): this;
|
|
52
|
+
whereDay(column: string, operator?: string | any, value?: any, boolean?: "and" | "or"): this;
|
|
53
|
+
orWhereDay(column: string, operator?: string | any, value?: any): this;
|
|
54
|
+
whereMonth(column: string, operator?: string | any, value?: any, boolean?: "and" | "or"): this;
|
|
55
|
+
orWhereMonth(column: string, operator?: string | any, value?: any): this;
|
|
56
|
+
whereYear(column: string, operator?: string | any, value?: any, boolean?: "and" | "or"): this;
|
|
57
|
+
orWhereYear(column: string, operator?: string | any, value?: any): this;
|
|
58
|
+
whereTime(column: string, operator?: string | any, value?: any, boolean?: "and" | "or"): this;
|
|
59
|
+
orWhereTime(column: string, operator?: string | any, value?: any): this;
|
|
41
60
|
whereRaw(sql: string, boolean?: "and" | "or", scope?: string): this;
|
|
42
61
|
whereColumn(first: string, operator: string, second: string, boolean?: "and" | "or"): this;
|
|
43
62
|
whereExists(sql: string, boolean?: "and" | "or", not?: boolean): this;
|
|
63
|
+
orWhereNull(column: string, scope?: string): this;
|
|
64
|
+
orWhereNotNull(column: string, scope?: string): this;
|
|
65
|
+
orWhereBetween(column: string, values: [any, any], scope?: string): this;
|
|
66
|
+
orWhereNotBetween(column: string, values: [any, any], scope?: string): this;
|
|
67
|
+
orWhereIn(column: string, values: any[], scope?: string): this;
|
|
68
|
+
orWhereNotIn(column: string, values: any[], scope?: string): this;
|
|
69
|
+
orWhereExists(sql: string): this;
|
|
70
|
+
orWhereNotExists(sql: string): this;
|
|
71
|
+
orWhereColumn(first: string, operator: string, second: string): this;
|
|
72
|
+
orWhereRaw(sql: string, scope?: string): this;
|
|
73
|
+
whereJsonContains(column: string, value: any, boolean?: "and" | "or", not?: boolean): this;
|
|
74
|
+
whereJsonLength(column: string, operator?: string | number, value?: number, boolean?: "and" | "or", not?: boolean): this;
|
|
75
|
+
whereLike(column: string, value: string, boolean?: "and" | "or", not?: boolean): this;
|
|
76
|
+
whereNotLike(column: string, value: string): this;
|
|
77
|
+
whereRegexp(column: string, value: string, boolean?: "and" | "or", not?: boolean): this;
|
|
78
|
+
whereFullText(columns: string | string[], value: string, boolean?: "and" | "or", not?: boolean): this;
|
|
79
|
+
whereAll(columns: string[], operator: string, value: any, boolean?: "and" | "or"): this;
|
|
80
|
+
whereAny(columns: string[], operator: string, value: any, boolean?: "and" | "or"): this;
|
|
44
81
|
orderBy(column: string, direction?: "asc" | "desc"): this;
|
|
82
|
+
latest(column?: string): this;
|
|
83
|
+
oldest(column?: string): this;
|
|
84
|
+
inRandomOrder(): this;
|
|
85
|
+
orderByDesc(column: string): this;
|
|
86
|
+
reorder(column?: string, direction?: "asc" | "desc"): this;
|
|
45
87
|
groupBy(...columns: string[]): this;
|
|
46
88
|
having(column: string, operator: string, value: any): this;
|
|
89
|
+
orHaving(column: string, operator: string, value: any): this;
|
|
90
|
+
havingRaw(sql: string, boolean?: "and" | "or"): this;
|
|
91
|
+
orHavingRaw(sql: string): this;
|
|
47
92
|
limit(count: number): this;
|
|
48
93
|
offset(count: number): this;
|
|
49
94
|
forPage(page: number, perPage?: number): this;
|
|
50
95
|
join(table: string, first: string, operator: string, second: string, type?: string): this;
|
|
51
96
|
leftJoin(table: string, first: string, operator: string, second: string): this;
|
|
52
97
|
rightJoin(table: string, first: string, operator: string, second: string): this;
|
|
98
|
+
crossJoin(table: string): this;
|
|
99
|
+
union(query: Builder<T> | string, all?: boolean): this;
|
|
100
|
+
unionAll(query: Builder<T> | string): this;
|
|
53
101
|
with(...relations: string[]): this;
|
|
54
102
|
withoutGlobalScope(scope: string): this;
|
|
55
103
|
withoutGlobalScopes(): this;
|
|
56
104
|
withTrashed(): this;
|
|
57
105
|
onlyTrashed(): this;
|
|
58
106
|
scope(name: string, ...args: any[]): this;
|
|
107
|
+
when(condition: any, callback: (query: this) => void | this, defaultCallback?: (query: this) => void | this): this;
|
|
108
|
+
unless(condition: any, callback: (query: this) => void | this, defaultCallback?: (query: this) => void | this): this;
|
|
109
|
+
tap(callback: (query: this) => void | this): this;
|
|
59
110
|
has(relationName: string, operator?: string | RelationConstraint, count?: number, callback?: RelationConstraint): this;
|
|
60
111
|
orHas(relationName: string, operator?: string | RelationConstraint, count?: number, callback?: RelationConstraint): this;
|
|
61
112
|
whereHas(relationName: string, callback?: RelationConstraint, operator?: string, count?: number): this;
|
|
@@ -68,13 +119,15 @@ export declare class Builder<T = Record<string, any>> {
|
|
|
68
119
|
withMin(relationName: string, column: string, alias?: string): this;
|
|
69
120
|
withMax(relationName: string, column: string, alias?: string): this;
|
|
70
121
|
addSelect(...columns: string[]): this;
|
|
122
|
+
selectRaw(sql: string): this;
|
|
123
|
+
fromSub(query: Builder<any> | string, as: string): this;
|
|
124
|
+
updateFrom(table: string, first: string, operator: string, second: string): this;
|
|
71
125
|
clone(): Builder<T>;
|
|
72
126
|
wrapColumn(value: string): string;
|
|
73
127
|
escapeValue(value: any): string;
|
|
74
|
-
private
|
|
75
|
-
private wrapValue;
|
|
76
|
-
private escape;
|
|
128
|
+
private compileWhereClause;
|
|
77
129
|
private compileWheres;
|
|
130
|
+
private compileNestedWheres;
|
|
78
131
|
private compileOrders;
|
|
79
132
|
private compileGroups;
|
|
80
133
|
private compileHavings;
|
|
@@ -86,6 +139,10 @@ export declare class Builder<T = Record<string, any>> {
|
|
|
86
139
|
get(): Promise<T[]>;
|
|
87
140
|
first(): Promise<T | null>;
|
|
88
141
|
find(id: any, column?: string): Promise<T | null>;
|
|
142
|
+
findOrFail(id: any, column?: string): Promise<T>;
|
|
143
|
+
firstOrFail(): Promise<T>;
|
|
144
|
+
firstOrCreate(attributes?: Partial<T>, values?: Partial<T>): Promise<T>;
|
|
145
|
+
updateOrCreate(attributes: Partial<T>, values?: Partial<T>): Promise<T>;
|
|
89
146
|
pluck(column: string): Promise<any[]>;
|
|
90
147
|
private aggregate;
|
|
91
148
|
count(column?: string): Promise<number>;
|
|
@@ -94,12 +151,33 @@ export declare class Builder<T = Record<string, any>> {
|
|
|
94
151
|
min(column: string): Promise<any>;
|
|
95
152
|
max(column: string): Promise<any>;
|
|
96
153
|
paginate(perPage?: number, page?: number): Promise<Paginator<T>>;
|
|
154
|
+
chunk(count: number, callback: (items: T[]) => void | Promise<void>): Promise<void>;
|
|
155
|
+
each(count: number, callback: (item: T) => void | Promise<void>): Promise<void>;
|
|
156
|
+
cursor(): AsyncGenerator<T>;
|
|
157
|
+
lazy(count?: number): AsyncGenerator<T>;
|
|
97
158
|
insert(data: Partial<T> | Partial<T>[]): Promise<any>;
|
|
98
159
|
insertGetId(data: Partial<T>, idColumn?: string): Promise<any>;
|
|
160
|
+
insertOrIgnore(data: Partial<T> | Partial<T>[]): Promise<any>;
|
|
161
|
+
upsert(data: Partial<T> | Partial<T>[], uniqueBy: string | string[], updateColumns?: string[]): Promise<any>;
|
|
99
162
|
update(data: Partial<T>): Promise<any>;
|
|
100
163
|
delete(): Promise<any>;
|
|
164
|
+
increment(column: string, amount?: number, extra?: Record<string, any>): Promise<any>;
|
|
165
|
+
decrement(column: string, amount?: number, extra?: Record<string, any>): Promise<any>;
|
|
101
166
|
restore(): Promise<any>;
|
|
102
167
|
exists(): Promise<boolean>;
|
|
168
|
+
doesntExist(): Promise<boolean>;
|
|
169
|
+
sole(): Promise<T>;
|
|
170
|
+
value(column: string): Promise<any>;
|
|
171
|
+
dump(): this;
|
|
172
|
+
dd(): never;
|
|
173
|
+
explain(): Promise<any[]>;
|
|
174
|
+
take(count: number): this;
|
|
175
|
+
skip(count: number): this;
|
|
176
|
+
lockForUpdate(): this;
|
|
177
|
+
sharedLock(): this;
|
|
178
|
+
skipLocked(): this;
|
|
179
|
+
noWait(): this;
|
|
180
|
+
private addDateWhere;
|
|
103
181
|
private getModelRelation;
|
|
104
182
|
private withAggregate;
|
|
105
183
|
}
|