11import { createId } from "@paralleldrive/cuid2" ;
22import { camelCase , snakeCase } from "change-case" ;
33import {
4- type Generated ,
54 type Insertable ,
65 type Kysely ,
76 type SelectQueryBuilder ,
7+ type Selectable ,
88 type TableMetadata ,
99 sql ,
1010} from "kysely" ;
@@ -165,8 +165,8 @@ export class Entity<DB, EntityName extends keyof DB & string> {
165165
166166 async createMany (
167167 data : Array < InsertableEntity < DB [ EntityName ] > > ,
168- ) : Promise < DB [ EntityName ] [ ] > {
169- const results : DB [ EntityName ] [ ] = [ ] ;
168+ ) : Promise < Selectable < DB [ EntityName ] > [ ] > {
169+ const results : Selectable < DB [ EntityName ] > [ ] = [ ] ;
170170 for ( const item of data ) {
171171 const inserted = await this . db
172172 . insertInto ( this . name )
@@ -183,14 +183,14 @@ export class Entity<DB, EntityName extends keyof DB & string> {
183183 } as any )
184184 . returningAll ( )
185185 . executeTakeFirstOrThrow ( ) ;
186- results . push ( inserted as unknown as DB [ EntityName ] ) ;
186+ results . push ( inserted as unknown as Selectable < DB [ EntityName ] > ) ;
187187 }
188188 return results ;
189189 }
190190
191191 async create (
192192 data : InsertableEntity < DB [ EntityName ] > ,
193- ) : Promise < DB [ EntityName ] > {
193+ ) : Promise < Selectable < DB [ EntityName ] > > {
194194 const inserted = await this . db
195195 . insertInto ( this . name )
196196 . values ( {
@@ -206,7 +206,7 @@ export class Entity<DB, EntityName extends keyof DB & string> {
206206 } as any )
207207 . returningAll ( )
208208 . executeTakeFirstOrThrow ( ) ;
209- return inserted as unknown as DB [ EntityName ] ;
209+ return inserted as unknown as Selectable < DB [ EntityName ] > ;
210210 }
211211
212212 async all < K extends keyof DB [ EntityName ] > (
@@ -215,7 +215,7 @@ export class Entity<DB, EntityName extends keyof DB & string> {
215215 limit ?: number ;
216216 offset ?: number ;
217217 } ,
218- ) : Promise < DB [ EntityName ] [ ] > {
218+ ) : Promise < Selectable < DB [ EntityName ] > [ ] > {
219219 let query = this . db . selectFrom ( this . name ) . selectAll ( ) ;
220220
221221 if ( filter ) {
@@ -234,12 +234,12 @@ export class Entity<DB, EntityName extends keyof DB & string> {
234234 }
235235 }
236236
237- return ( await query . execute ( ) ) as DB [ EntityName ] [ ] ;
237+ return ( await query . execute ( ) ) as unknown as Selectable < DB [ EntityName ] > [ ] ;
238238 }
239239
240240 async get < K extends keyof DB [ EntityName ] > (
241241 filter ?: Partial < Pick < DB [ EntityName ] , K > > ,
242- ) : Promise < DB [ EntityName ] | undefined > {
242+ ) : Promise < Selectable < DB [ EntityName ] > | undefined > {
243243 const result = await this . all ( filter ) ;
244244 if ( result . length === 0 ) return undefined ;
245245 return result [ 0 ] ;
0 commit comments