@bunnykit/orm 0.1.11 → 0.1.12

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 CHANGED
@@ -1262,7 +1262,16 @@ export class User extends Model {
1262
1262
  }
1263
1263
  ```
1264
1264
 
1265
- Editors that include the generated `.d.ts` files in `tsconfig.json` will understand `user.name`, `user.email`, etc. The generated files can be safely **gitignored** and regenerated whenever your schema changes.
1265
+ Editors that include the generated `.d.ts` files in `tsconfig.json` will understand `user.name`, `user.email`, etc. The same generated attributes are also used for column-name autocomplete in model and builder APIs:
1266
+
1267
+ ```ts
1268
+ await User.where("email", "alice@example.com").first();
1269
+ await User.where({ email: "alice@example.com" }).first();
1270
+ await User.orderBy("created_at").get();
1271
+ await User.create({ id: 1, name: "Alice", email: "alice@example.com" });
1272
+ ```
1273
+
1274
+ Column arguments still accept raw strings for joins, aliases, expressions, and advanced SQL, so autocomplete is helpful without blocking escape hatches. The generated files can be safely **gitignored** and regenerated whenever your schema changes.
1266
1275
 
1267
1276
  If you still want generated base classes, use the programmatic generator with `{ stubs: true }`.
1268
1277
 
@@ -14,7 +14,7 @@ export { MySqlGrammar } from "./schema/grammars/MySqlGrammar.js";
14
14
  export { PostgresGrammar } from "./schema/grammars/PostgresGrammar.js";
15
15
  export { Builder } from "./query/Builder.js";
16
16
  export { Model, HasMany, BelongsTo, HasOne, HasManyThrough, HasOneThrough } from "./model/Model.js";
17
- export type { ModelConstructor, GlobalScope, CastDefinition, CastsAttributes } from "./model/Model.js";
17
+ export type { ModelAttributeInput, ModelAttributes, ModelColumn, ModelColumnValue, ModelConstructor, GlobalScope, CastDefinition, CastsAttributes, } from "./model/Model.js";
18
18
  export { ModelNotFoundError } from "./model/ModelNotFoundError.js";
19
19
  export { ObserverRegistry, type ObserverContract } from "./model/Observer.js";
20
20
  export { MorphMap } from "./model/MorphMap.js";
@@ -4,6 +4,15 @@ import { MorphTo, MorphOne, MorphMany, MorphToMany } from "./MorphRelations.js";
4
4
  import { BelongsToMany } from "./BelongsToMany.js";
5
5
  export type ModelConstructor<T extends Model = Model> = (new (...args: any[]) => T) & Omit<typeof Model, "prototype">;
6
6
  export type GlobalScope = (builder: Builder<any>, model: ModelConstructor) => void;
7
+ export type LiteralUnion<T extends string> = T | (string & {});
8
+ type BaseModelInstanceKey = "$attributes" | "$original" | "$exists" | "$relations" | "$casts" | "$connection" | "fill" | "setConnection" | "getConnection" | "isFillable" | "getAttribute" | "setAttribute" | "castAttribute" | "serializeCastAttribute" | "mergeCasts" | "getDirty" | "isDirty" | "save" | "updateTimestamps" | "touch" | "increment" | "decrement" | "load" | "delete" | "restore" | "forceDelete" | "refresh" | "toJSON" | "toString" | "freshTimestamp" | "setRelation" | "getRelation" | "hasMany" | "belongsTo" | "hasOne" | "hasManyThrough" | "hasOneThrough" | "belongsToMany" | "morphTo" | "morphOne" | "morphMany" | "morphToMany" | "morphedByMany";
9
+ export type ModelInstanceAttributeKeys<T> = Extract<Exclude<keyof T, BaseModelInstanceKey>, string>;
10
+ export type ModelAttributes<T> = T extends {
11
+ $attributes: Record<string, any>;
12
+ } ? string extends keyof T["$attributes"] ? Pick<T, ModelInstanceAttributeKeys<T>> : T["$attributes"] : T;
13
+ export type ModelColumn<T> = LiteralUnion<Extract<keyof ModelAttributes<T>, string>>;
14
+ export type ModelColumnValue<T, K> = K extends keyof ModelAttributes<T> ? ModelAttributes<T>[K] : any;
15
+ export type ModelAttributeInput<T> = Partial<ModelAttributes<T>> & Record<string, any>;
7
16
  export type CastDefinition = string | CastsAttributes | (new (...args: any[]) => CastsAttributes);
8
17
  export interface CastsAttributes {
9
18
  get(model: Model, key: string, value: any, attributes: Record<string, any>): any;
@@ -110,33 +119,37 @@ export declare class Model<T extends Record<string, any> = Record<string, any>>
110
119
  static applyGlobalScopes(builder: Builder<any>): void;
111
120
  static getQualifiedDeletedAtColumn(): string;
112
121
  static shouldAutoGeneratePrimaryKey(): Promise<boolean>;
113
- static create<M extends ModelConstructor>(this: M, attributes: Partial<InstanceType<M> extends Model<infer U> ? U : Record<string, any>>): Promise<InstanceType<M>>;
122
+ static create<M extends ModelConstructor>(this: M, attributes: ModelAttributeInput<InstanceType<M>>): Promise<InstanceType<M>>;
114
123
  static find<M extends ModelConstructor>(this: M, id: any): Promise<InstanceType<M> | null>;
115
124
  static findOrFail<M extends ModelConstructor>(this: M, id: any): Promise<InstanceType<M>>;
116
125
  static first<M extends ModelConstructor>(this: M): Promise<InstanceType<M> | null>;
117
126
  static firstOrFail<M extends ModelConstructor>(this: M): Promise<InstanceType<M>>;
118
- static firstOrCreate<M extends ModelConstructor>(this: M, attributes?: Record<string, any>, values?: Record<string, any>): Promise<InstanceType<M>>;
119
- static updateOrCreate<M extends ModelConstructor>(this: M, attributes: Record<string, any>, values?: Record<string, any>): Promise<InstanceType<M>>;
120
- static where<M extends ModelConstructor>(this: M, column: string | Record<string, any>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
121
- static orderBy<M extends ModelConstructor>(this: M, column: string, direction?: "asc" | "desc"): Builder<InstanceType<M>>;
122
- static whereIn<M extends ModelConstructor>(this: M, column: string, values: any[]): Builder<InstanceType<M>>;
123
- static whereNull<M extends ModelConstructor>(this: M, column: string): Builder<InstanceType<M>>;
124
- static whereNotNull<M extends ModelConstructor>(this: M, column: string): Builder<InstanceType<M>>;
125
- static orWhere<M extends ModelConstructor>(this: M, column: string | Record<string, any>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
126
- static whereNot<M extends ModelConstructor>(this: M, column: string | Record<string, any>, value?: any): Builder<InstanceType<M>>;
127
- static orWhereNot<M extends ModelConstructor>(this: M, column: string | Record<string, any>, value?: any): Builder<InstanceType<M>>;
128
- static whereDate<M extends ModelConstructor>(this: M, column: string, operator?: string | any, value?: any): Builder<InstanceType<M>>;
129
- static orWhereDate<M extends ModelConstructor>(this: M, column: string, operator?: string | any, value?: any): Builder<InstanceType<M>>;
130
- static whereDay<M extends ModelConstructor>(this: M, column: string, operator?: string | any, value?: any): Builder<InstanceType<M>>;
131
- static orWhereDay<M extends ModelConstructor>(this: M, column: string, operator?: string | any, value?: any): Builder<InstanceType<M>>;
132
- static whereMonth<M extends ModelConstructor>(this: M, column: string, operator?: string | any, value?: any): Builder<InstanceType<M>>;
133
- static orWhereMonth<M extends ModelConstructor>(this: M, column: string, operator?: string | any, value?: any): Builder<InstanceType<M>>;
134
- static whereYear<M extends ModelConstructor>(this: M, column: string, operator?: string | any, value?: any): Builder<InstanceType<M>>;
135
- static orWhereYear<M extends ModelConstructor>(this: M, column: string, operator?: string | any, value?: any): Builder<InstanceType<M>>;
136
- static whereTime<M extends ModelConstructor>(this: M, column: string, operator?: string | any, value?: any): Builder<InstanceType<M>>;
137
- static orWhereTime<M extends ModelConstructor>(this: M, column: string, operator?: string | any, value?: any): Builder<InstanceType<M>>;
138
- static latest<M extends ModelConstructor>(this: M, column?: string): Builder<InstanceType<M>>;
139
- static oldest<M extends ModelConstructor>(this: M, column?: string): Builder<InstanceType<M>>;
127
+ static firstOrCreate<M extends ModelConstructor>(this: M, attributes?: ModelAttributeInput<InstanceType<M>>, values?: ModelAttributeInput<InstanceType<M>>): Promise<InstanceType<M>>;
128
+ static updateOrCreate<M extends ModelConstructor>(this: M, attributes: ModelAttributeInput<InstanceType<M>>, values?: ModelAttributeInput<InstanceType<M>>): Promise<InstanceType<M>>;
129
+ static where<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, value: any): Builder<InstanceType<M>>;
130
+ static where<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, operator: string, value: any): Builder<InstanceType<M>>;
131
+ static where<M extends ModelConstructor>(this: M, column: ModelAttributeInput<InstanceType<M>>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
132
+ static orderBy<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, direction?: "asc" | "desc"): Builder<InstanceType<M>>;
133
+ static whereIn<M extends ModelConstructor, K extends ModelColumn<InstanceType<M>>>(this: M, column: K, values: ModelColumnValue<InstanceType<M>, K>[]): Builder<InstanceType<M>>;
134
+ static whereNull<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>): Builder<InstanceType<M>>;
135
+ static whereNotNull<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>): Builder<InstanceType<M>>;
136
+ static orWhere<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, value: any): Builder<InstanceType<M>>;
137
+ static orWhere<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, operator: string, value: any): Builder<InstanceType<M>>;
138
+ static orWhere<M extends ModelConstructor>(this: M, column: ModelAttributeInput<InstanceType<M>>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
139
+ static whereNot<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>> | ModelAttributeInput<InstanceType<M>>, value?: any): Builder<InstanceType<M>>;
140
+ static orWhereNot<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>> | ModelAttributeInput<InstanceType<M>>, value?: any): Builder<InstanceType<M>>;
141
+ static whereDate<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
142
+ static orWhereDate<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
143
+ static whereDay<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
144
+ static orWhereDay<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
145
+ static whereMonth<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
146
+ static orWhereMonth<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
147
+ static whereYear<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
148
+ static orWhereYear<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
149
+ static whereTime<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
150
+ static orWhereTime<M extends ModelConstructor>(this: M, column: ModelColumn<InstanceType<M>>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
151
+ static latest<M extends ModelConstructor>(this: M, column?: ModelColumn<InstanceType<M>>): Builder<InstanceType<M>>;
152
+ static oldest<M extends ModelConstructor>(this: M, column?: ModelColumn<InstanceType<M>>): Builder<InstanceType<M>>;
140
153
  static when<M extends ModelConstructor>(this: M, condition: any, callback: (query: Builder<any>) => void | Builder<any>, defaultCallback?: (query: Builder<any>) => void | Builder<any>): Builder<InstanceType<M>>;
141
154
  static unless<M extends ModelConstructor>(this: M, condition: any, callback: (query: Builder<any>) => void | Builder<any>, defaultCallback?: (query: Builder<any>) => void | Builder<any>): Builder<InstanceType<M>>;
142
155
  static tap<M extends ModelConstructor>(this: M, callback: (query: Builder<any>) => void | Builder<any>): Builder<InstanceType<M>>;
@@ -155,10 +168,10 @@ export declare class Model<T extends Record<string, any> = Record<string, any>>
155
168
  static whereHas<M extends ModelConstructor>(this: M, relationName: string, callback?: (query: Builder<any>) => void | Builder<any>, operator?: string, count?: number): Builder<InstanceType<M>>;
156
169
  static doesntHave<M extends ModelConstructor>(this: M, relationName: string): Builder<InstanceType<M>>;
157
170
  static withCount<M extends ModelConstructor>(this: M, relationName: string, alias?: string): Builder<InstanceType<M>>;
158
- static withSum<M extends ModelConstructor>(this: M, relationName: string, column: string, alias?: string): Builder<InstanceType<M>>;
159
- static withAvg<M extends ModelConstructor>(this: M, relationName: string, column: string, alias?: string): Builder<InstanceType<M>>;
160
- static withMin<M extends ModelConstructor>(this: M, relationName: string, column: string, alias?: string): Builder<InstanceType<M>>;
161
- static withMax<M extends ModelConstructor>(this: M, relationName: string, column: string, alias?: string): Builder<InstanceType<M>>;
171
+ static withSum<M extends ModelConstructor>(this: M, relationName: string, column: ModelColumn<InstanceType<M>>, alias?: string): Builder<InstanceType<M>>;
172
+ static withAvg<M extends ModelConstructor>(this: M, relationName: string, column: ModelColumn<InstanceType<M>>, alias?: string): Builder<InstanceType<M>>;
173
+ static withMin<M extends ModelConstructor>(this: M, relationName: string, column: ModelColumn<InstanceType<M>>, alias?: string): Builder<InstanceType<M>>;
174
+ static withMax<M extends ModelConstructor>(this: M, relationName: string, column: ModelColumn<InstanceType<M>>, alias?: string): Builder<InstanceType<M>>;
162
175
  static all<M extends ModelConstructor>(this: M): Promise<InstanceType<M>[]>;
163
176
  static paginate<M extends ModelConstructor>(this: M, perPage?: number, page?: number): Promise<import("../query/Builder.js").Paginator<InstanceType<M>>>;
164
177
  static chunk<M extends ModelConstructor>(this: M, count: number, callback: (items: InstanceType<M>[]) => void | Promise<void>): Promise<void>;
@@ -167,7 +180,7 @@ export declare class Model<T extends Record<string, any> = Record<string, any>>
167
180
  static lazy<M extends ModelConstructor>(this: M, count?: number): AsyncGenerator<InstanceType<M>>;
168
181
  static eagerLoadRelations(models: Model[], relations: string[]): Promise<void>;
169
182
  static eagerLoadRelation(models: Model[], relationName: string): Promise<void>;
170
- fill(attributes: Partial<T>): this;
183
+ fill(attributes: Partial<T> | ModelAttributeInput<this>): this;
171
184
  setConnection(connection: Connection): this;
172
185
  getConnection(): Connection;
173
186
  isFillable(key: string): boolean;
@@ -185,8 +198,8 @@ export declare class Model<T extends Record<string, any> = Record<string, any>>
185
198
  save(): Promise<this>;
186
199
  updateTimestamps(): void;
187
200
  touch(): Promise<boolean>;
188
- increment(column: string, amount?: number, extra?: Record<string, any>): Promise<this>;
189
- decrement(column: string, amount?: number, extra?: Record<string, any>): Promise<this>;
201
+ increment<K extends ModelColumn<this>>(column: K, amount?: number, extra?: ModelAttributeInput<this>): Promise<this>;
202
+ decrement<K extends ModelColumn<this>>(column: K, amount?: number, extra?: ModelAttributeInput<this>): Promise<this>;
190
203
  load(...relations: string[]): Promise<this>;
191
204
  delete(): Promise<boolean>;
192
205
  restore(): Promise<boolean>;
@@ -209,3 +222,4 @@ export declare class Model<T extends Record<string, any> = Record<string, any>>
209
222
  morphToMany<R extends Model>(related: ModelConstructor<R>, name: string, table?: string, foreignPivotKey?: string, relatedPivotKey?: string, parentKey?: string, relatedKey?: string): MorphToMany<R>;
210
223
  morphedByMany<R extends Model>(related: ModelConstructor<R>, name: string, table?: string, foreignPivotKey?: string, relatedPivotKey?: string, parentKey?: string, relatedKey?: string): MorphToMany<R>;
211
224
  }
225
+ export {};
@@ -1,5 +1,5 @@
1
1
  import type { Model } from "./Model.js";
2
- export interface ObserverContract<T extends Model = Model> {
2
+ export interface ObserverContract<T extends Model<any> = Model<any>> {
3
3
  creating?(model: T): Promise<void> | void;
4
4
  created?(model: T): Promise<void> | void;
5
5
  updating?(model: T): Promise<void> | void;
@@ -15,5 +15,5 @@ export declare class ObserverRegistry {
15
15
  private static observers;
16
16
  static register(modelClass: typeof Model, observer: ObserverContract): void;
17
17
  static get(modelClass: typeof Model): ObserverContract[];
18
- static dispatch<T extends Model>(event: keyof ObserverContract, model: T): Promise<void>;
18
+ static dispatch<T extends Model<any>>(event: keyof ObserverContract, model: T): Promise<void>;
19
19
  }
@@ -1,6 +1,6 @@
1
1
  import { Connection } from "../connection/Connection.js";
2
2
  import type { WhereClause, OrderClause, HavingClause, UnionClause } from "../types/index.js";
3
- import type { ModelConstructor } from "../model/Model.js";
3
+ import type { ModelAttributeInput, ModelColumn, ModelColumnValue, ModelConstructor } from "../model/Model.js";
4
4
  type RelationConstraint = (query: Builder<any>) => void | Builder<any>;
5
5
  export interface Paginator<T> {
6
6
  data: T[];
@@ -34,59 +34,63 @@ export declare class Builder<T = Record<string, any>> {
34
34
  private get grammar();
35
35
  setModel(model: ModelConstructor): this;
36
36
  table(table: string): this;
37
- select(...columns: string[]): this;
37
+ select(...columns: ModelColumn<T>[]): this;
38
38
  distinct(): this;
39
- where(column: string | Record<string, any> | ((query: Builder<T>) => void), operator?: string | any, value?: any, boolean?: "and" | "or", scope?: string): this;
39
+ where(column: ModelColumn<T>, value: any): this;
40
+ where(column: ModelColumn<T>, operator: string, value: any, boolean?: "and" | "or", scope?: string): this;
41
+ where(column: ModelAttributeInput<T> | ((query: Builder<T>) => void), operator?: string | any, value?: any, boolean?: "and" | "or", scope?: string): this;
40
42
  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;
44
- whereIn(column: string, values: any[], boolean?: "and" | "or", scope?: string): this;
45
- whereNotIn(column: string, values: any[], boolean?: "and" | "or", scope?: string): this;
46
- whereNull(column: string, boolean?: "and" | "or", scope?: string): this;
47
- whereNotNull(column: string, boolean?: "and" | "or", scope?: string): this;
48
- whereBetween(column: string, values: [any, any], boolean?: "and" | "or", scope?: string): this;
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;
43
+ orWhere(column: ModelColumn<T>, value: any): this;
44
+ orWhere(column: ModelColumn<T>, operator: string, value: any): this;
45
+ orWhere(column: ModelAttributeInput<T> | ((query: Builder<T>) => void), operator?: string | any, value?: any): this;
46
+ whereNot(column: ModelColumn<T> | ModelAttributeInput<T>, value?: any, boolean?: "and" | "or"): this;
47
+ orWhereNot(column: ModelColumn<T> | ModelAttributeInput<T>, value?: any): this;
48
+ whereIn<K extends ModelColumn<T>>(column: K, values: ModelColumnValue<T, K>[], boolean?: "and" | "or", scope?: string): this;
49
+ whereNotIn<K extends ModelColumn<T>>(column: K, values: ModelColumnValue<T, K>[], boolean?: "and" | "or", scope?: string): this;
50
+ whereNull(column: ModelColumn<T>, boolean?: "and" | "or", scope?: string): this;
51
+ whereNotNull(column: ModelColumn<T>, boolean?: "and" | "or", scope?: string): this;
52
+ whereBetween<K extends ModelColumn<T>>(column: K, values: [ModelColumnValue<T, K>, ModelColumnValue<T, K>], boolean?: "and" | "or", scope?: string): this;
53
+ whereNotBetween<K extends ModelColumn<T>>(column: K, values: [ModelColumnValue<T, K>, ModelColumnValue<T, K>], boolean?: "and" | "or", scope?: string): this;
54
+ whereDate(column: ModelColumn<T>, operator?: string | any, value?: any, boolean?: "and" | "or"): this;
55
+ orWhereDate(column: ModelColumn<T>, operator?: string | any, value?: any): this;
56
+ whereDay(column: ModelColumn<T>, operator?: string | any, value?: any, boolean?: "and" | "or"): this;
57
+ orWhereDay(column: ModelColumn<T>, operator?: string | any, value?: any): this;
58
+ whereMonth(column: ModelColumn<T>, operator?: string | any, value?: any, boolean?: "and" | "or"): this;
59
+ orWhereMonth(column: ModelColumn<T>, operator?: string | any, value?: any): this;
60
+ whereYear(column: ModelColumn<T>, operator?: string | any, value?: any, boolean?: "and" | "or"): this;
61
+ orWhereYear(column: ModelColumn<T>, operator?: string | any, value?: any): this;
62
+ whereTime(column: ModelColumn<T>, operator?: string | any, value?: any, boolean?: "and" | "or"): this;
63
+ orWhereTime(column: ModelColumn<T>, operator?: string | any, value?: any): this;
60
64
  whereRaw(sql: string, boolean?: "and" | "or", scope?: string): this;
61
65
  whereColumn(first: string, operator: string, second: string, boolean?: "and" | "or"): this;
62
66
  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;
67
+ orWhereNull(column: ModelColumn<T>, scope?: string): this;
68
+ orWhereNotNull(column: ModelColumn<T>, scope?: string): this;
69
+ orWhereBetween<K extends ModelColumn<T>>(column: K, values: [ModelColumnValue<T, K>, ModelColumnValue<T, K>], scope?: string): this;
70
+ orWhereNotBetween<K extends ModelColumn<T>>(column: K, values: [ModelColumnValue<T, K>, ModelColumnValue<T, K>], scope?: string): this;
71
+ orWhereIn<K extends ModelColumn<T>>(column: K, values: ModelColumnValue<T, K>[], scope?: string): this;
72
+ orWhereNotIn<K extends ModelColumn<T>>(column: K, values: ModelColumnValue<T, K>[], scope?: string): this;
69
73
  orWhereExists(sql: string): this;
70
74
  orWhereNotExists(sql: string): this;
71
75
  orWhereColumn(first: string, operator: string, second: string): this;
72
76
  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;
81
- orderBy(column: string, direction?: "asc" | "desc"): this;
82
- latest(column?: string): this;
83
- oldest(column?: string): this;
77
+ whereJsonContains(column: ModelColumn<T>, value: any, boolean?: "and" | "or", not?: boolean): this;
78
+ whereJsonLength(column: ModelColumn<T>, operator?: string | number, value?: number, boolean?: "and" | "or", not?: boolean): this;
79
+ whereLike(column: ModelColumn<T>, value: string, boolean?: "and" | "or", not?: boolean): this;
80
+ whereNotLike(column: ModelColumn<T>, value: string): this;
81
+ whereRegexp(column: ModelColumn<T>, value: string, boolean?: "and" | "or", not?: boolean): this;
82
+ whereFullText(columns: ModelColumn<T> | ModelColumn<T>[], value: string, boolean?: "and" | "or", not?: boolean): this;
83
+ whereAll(columns: ModelColumn<T>[], operator: string, value: any, boolean?: "and" | "or"): this;
84
+ whereAny(columns: ModelColumn<T>[], operator: string, value: any, boolean?: "and" | "or"): this;
85
+ orderBy(column: ModelColumn<T>, direction?: "asc" | "desc"): this;
86
+ latest(column?: ModelColumn<T>): this;
87
+ oldest(column?: ModelColumn<T>): this;
84
88
  inRandomOrder(): this;
85
- orderByDesc(column: string): this;
86
- reorder(column?: string, direction?: "asc" | "desc"): this;
87
- groupBy(...columns: string[]): this;
88
- having(column: string, operator: string, value: any): this;
89
- orHaving(column: string, operator: string, value: any): this;
89
+ orderByDesc(column: ModelColumn<T>): this;
90
+ reorder(column?: ModelColumn<T>, direction?: "asc" | "desc"): this;
91
+ groupBy(...columns: ModelColumn<T>[]): this;
92
+ having(column: ModelColumn<T>, operator: string, value: any): this;
93
+ orHaving(column: ModelColumn<T>, operator: string, value: any): this;
90
94
  havingRaw(sql: string, boolean?: "and" | "or"): this;
91
95
  orHavingRaw(sql: string): this;
92
96
  limit(count: number): this;
@@ -114,11 +118,11 @@ export declare class Builder<T = Record<string, any>> {
114
118
  doesntHave(relationName: string, callback?: RelationConstraint): this;
115
119
  whereDoesntHave(relationName: string, callback?: RelationConstraint): this;
116
120
  withCount(relationName: string, alias?: string): this;
117
- withSum(relationName: string, column: string, alias?: string): this;
118
- withAvg(relationName: string, column: string, alias?: string): this;
119
- withMin(relationName: string, column: string, alias?: string): this;
120
- withMax(relationName: string, column: string, alias?: string): this;
121
- addSelect(...columns: string[]): this;
121
+ withSum(relationName: string, column: ModelColumn<T>, alias?: string): this;
122
+ withAvg(relationName: string, column: ModelColumn<T>, alias?: string): this;
123
+ withMin(relationName: string, column: ModelColumn<T>, alias?: string): this;
124
+ withMax(relationName: string, column: ModelColumn<T>, alias?: string): this;
125
+ addSelect(...columns: ModelColumn<T>[]): this;
122
126
  selectRaw(sql: string): this;
123
127
  fromSub(query: Builder<any> | string, as: string): this;
124
128
  updateFrom(table: string, first: string, operator: string, second: string): this;
@@ -138,36 +142,36 @@ export declare class Builder<T = Record<string, any>> {
138
142
  toSql(): string;
139
143
  get(): Promise<T[]>;
140
144
  first(): Promise<T | null>;
141
- find(id: any, column?: string): Promise<T | null>;
142
- findOrFail(id: any, column?: string): Promise<T>;
145
+ find(id: any, column?: ModelColumn<T>): Promise<T | null>;
146
+ findOrFail(id: any, column?: ModelColumn<T>): Promise<T>;
143
147
  firstOrFail(): Promise<T>;
144
- firstOrCreate(attributes?: Partial<T>, values?: Partial<T>): Promise<T>;
145
- updateOrCreate(attributes: Partial<T>, values?: Partial<T>): Promise<T>;
146
- pluck(column: string): Promise<any[]>;
148
+ firstOrCreate(attributes?: ModelAttributeInput<T>, values?: ModelAttributeInput<T>): Promise<T>;
149
+ updateOrCreate(attributes: ModelAttributeInput<T>, values?: ModelAttributeInput<T>): Promise<T>;
150
+ pluck<K extends ModelColumn<T>>(column: K): Promise<ModelColumnValue<T, K>[]>;
147
151
  private aggregate;
148
- count(column?: string): Promise<number>;
149
- sum(column: string): Promise<number>;
150
- avg(column: string): Promise<number>;
151
- min(column: string): Promise<any>;
152
- max(column: string): Promise<any>;
152
+ count(column?: ModelColumn<T> | "*"): Promise<number>;
153
+ sum(column: ModelColumn<T>): Promise<number>;
154
+ avg(column: ModelColumn<T>): Promise<number>;
155
+ min<K extends ModelColumn<T>>(column: K): Promise<ModelColumnValue<T, K> | null>;
156
+ max<K extends ModelColumn<T>>(column: K): Promise<ModelColumnValue<T, K> | null>;
153
157
  paginate(perPage?: number, page?: number): Promise<Paginator<T>>;
154
158
  chunk(count: number, callback: (items: T[]) => void | Promise<void>): Promise<void>;
155
159
  each(count: number, callback: (item: T) => void | Promise<void>): Promise<void>;
156
160
  cursor(): AsyncGenerator<T>;
157
161
  lazy(count?: number): AsyncGenerator<T>;
158
- insert(data: Partial<T> | Partial<T>[]): Promise<any>;
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>;
162
- update(data: Partial<T>): Promise<any>;
162
+ insert(data: ModelAttributeInput<T> | ModelAttributeInput<T>[]): Promise<any>;
163
+ insertGetId(data: ModelAttributeInput<T>, idColumn?: ModelColumn<T>): Promise<any>;
164
+ insertOrIgnore(data: ModelAttributeInput<T> | ModelAttributeInput<T>[]): Promise<any>;
165
+ upsert(data: ModelAttributeInput<T> | ModelAttributeInput<T>[], uniqueBy: ModelColumn<T> | ModelColumn<T>[], updateColumns?: ModelColumn<T>[]): Promise<any>;
166
+ update(data: ModelAttributeInput<T>): Promise<any>;
163
167
  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>;
168
+ increment(column: ModelColumn<T>, amount?: number, extra?: ModelAttributeInput<T>): Promise<any>;
169
+ decrement(column: ModelColumn<T>, amount?: number, extra?: ModelAttributeInput<T>): Promise<any>;
166
170
  restore(): Promise<any>;
167
171
  exists(): Promise<boolean>;
168
172
  doesntExist(): Promise<boolean>;
169
173
  sole(): Promise<T>;
170
- value(column: string): Promise<any>;
174
+ value<K extends ModelColumn<T>>(column: K): Promise<ModelColumnValue<T, K> | null>;
171
175
  dump(): this;
172
176
  dd(): never;
173
177
  explain(): Promise<any[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunnykit/orm",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "An Eloquent-inspired ORM for Bun's native SQL client supporting SQLite, MySQL, and PostgreSQL.",
5
5
  "license": "MIT",
6
6
  "packageManager": "bun@1.3.12",