@@ -56,9 +56,6 @@ Configuration options for the abstract repository:
5656
5757| Option | Type | Default | Description |
5858| ------------------| --------------------------| -------------------------| -------------------------------------------------------|
59- | ` autoGenerateId ` | ` boolean ` | ` false ` | Whether to auto-generate a UUIDv4 for the primary key |
60- | ` idField ` | ` string ` | ` 'id' ` | Name of the primary key field |
61- | ` idGenerator ` | ` () => string \| number ` | ` UUIDv4 ` | Function for generating unique IDs |
6259| ` logger ` | ` Logger ` | ` NestJS default Logger ` | Optional NestJS logger instance for internal logging |
6360
6461---
@@ -67,19 +64,19 @@ Configuration options for the abstract repository:
6764
6865All methods return Promises.
6966
70- | Method | Parameters | Description | | |
71- | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------| ------------------------------------------------- | ------------ | ----------------------------------------|
72- | ` create(dto, options?) ` | ` dto: CreationAttributes<TModel> ` , ` options?: CreateOptions<TModel> ` | Creates a new record | | |
73- | ` insert(dto, options?) ` | Same as ` create ` | Alias for ` create ` | | |
74- | ` insertMany(dtos, options?) ` | ` dtos: CreationAttributes<TModel>[] ` , ` options?: BulkCreateOptions<Attributes<TModel>> ` | Creates multiple records | | |
75- | ` findByPk(primaryKey, options?) ` | ` primaryKey: string \| number ` , ` options?: Omit<FindOptions, 'where'> ` | Find record by primary key | | |
76- | ` findOne(query?, options?) ` | ` query?: WhereOptions ` , ` options?: Omit<FindOptions, 'where'> ` | Find single record by query | | |
77- | ` findAll(query?, options?) ` | ` query?: WhereOptions ` , ` options?: Omit<FindOptions, 'where'> ` | Find all matching records | | |
78- | ` findAllPaginated(limit, offset?, query?, options?) ` | ` limit: number ` , ` offset?: number ` , ` query?: WhereOptions ` , \ ` options?: Omit\ < FindAndCountOptions, 'where' | 'offset' | 'limit'>\ ` | Find paginated records and total count |
79- | ` updateByPk(primaryKey, dto, options?) ` | ` primaryKey: string \| number ` , ` dto: Partial<Attributes<TModel>> ` , ` options?: SaveOptions ` | Update record by primary key | | |
80- | ` deleteByPk(primaryKey, options?) ` | ` primaryKey: string \| number ` , ` options?: InstanceDestroyOptions ` | Delete (soft/hard) record by primary key | | |
81- | ` restoreByPk(primaryKey, options?) ` | ` primaryKey: string \| number ` , ` options?: InstanceRestoreOptions ` | Restore previously soft-deleted record | | |
82- | ` transaction(runInTransaction) ` | ` (transaction: Transaction) => Promise<R> ` | Execute callback within a Sequelize transaction | | |
67+ | Method | Parameters | Description |
68+ | -----------------------------------------| ------------------------------------------------------------------------------------------------------------------------------------| -------------------------------------------------|
69+ | ` create(dto, options?) ` | ` dto: CreationAttributes<TModel> ` , ` options?: CreateOptions<TModel> ` | Creates a new record |
70+ | ` insert(dto, options?) ` | Same as ` create ` | Alias for ` create ` |
71+ | ` insertMany(dtos, options?) ` | ` dtos: CreationAttributes<TModel>[] ` , ` options?: BulkCreateOptions<Attributes<TModel>> ` | Creates multiple records |
72+ | ` findByPk(primaryKey, options?) ` | ` primaryKey: string \| number ` , ` options?: Omit<FindOptions, 'where'> ` | Find record by primary key |
73+ | ` findOne(query?, options?) ` | ` query?: WhereOptions ` , ` options?: Omit<FindOptions, 'where'> ` | Find single record by query |
74+ | ` findAll(query?, options?) ` | ` query?: WhereOptions ` , ` options?: Omit<FindOptions, 'where'> ` | Find all matching records |
75+ | ` findAllPaginated(options?) ` | ` limit? : number ` , ` offset?: number ` , ` query?: WhereOptions ` , ` options?: Omit<FindAndCountOptions, 'where' \ | 'offset' \ | 'limit'> ` | Find paginated records and total count |
76+ | ` updateByPk(primaryKey, dto, options?) ` | ` primaryKey: string \| number ` , ` dto: Partial<Attributes<TModel>> ` , ` options?: SaveOptions ` | Update record by primary key |
77+ | ` deleteByPk(primaryKey, options?) ` | ` primaryKey: string \| number ` , ` options?: InstanceDestroyOptions ` | Delete (soft/hard) record by primary key |
78+ | ` restoreByPk(primaryKey, options?) ` | ` primaryKey: string \| number ` , ` options?: InstanceRestoreOptions ` | Restore previously soft-deleted record |
79+ | ` transaction(runInTransaction) ` | ` (transaction: Transaction) => Promise<R> ` | Execute callback within a Sequelize transaction |
8380
8481---
8582
@@ -91,6 +88,7 @@ All methods return Promises.
9188@Table ({ tableName: ' users' , paranoid: true })
9289export class User extends Model <User > {
9390 @PrimaryKey
91+ @Default (DataType .UUIDV4 )
9492 @Column
9593 user_id: string ;
9694
@@ -112,10 +110,7 @@ import { AbstractRepository } from 'nest-sequelize-repository';
112110@Injectable ()
113111export class UserRepository extends AbstractRepository <User > {
114112 constructor (@InjectModel (User ) userModel : typeof User ) {
115- super (userModel , {
116- autoGenerateId: true ,
117- idField: ' user_id' ,
118- });
113+ super (userModel );
119114 }
120115}
121116```
@@ -151,9 +146,6 @@ You can pass options when instantiating:
151146
152147``` ts
153148{
154- autoGenerateId : true , // optional
155- idField : ' user_id' , // optional, default field is 'id'
156- idGenerator : myGenerateIdFunc , // optional, default is UUIDv4
157149 logger : new MyCustomLogger (' MyRepo' ), // optional
158150}
159151```
0 commit comments