Skip to content

Commit

Permalink
Merge pull request #65 from UN-OCHA/create-many-sequelize
Browse files Browse the repository at this point in the history
Define `createMany` for sequelize models
  • Loading branch information
czmj authored Dec 2, 2021
2 parents 8ee9e61 + ee85154 commit 12b56f1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/db/util/sequelize-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
defineRawModel,
ModelInitializer,
CreateFn,
CreateManyFn,
UpdateFn,
} from './raw-model';
import { FieldDefinition } from './model-definition';
Expand Down Expand Up @@ -103,6 +104,17 @@ export const defineSequelizeModel =
);
};

const createMany: CreateManyFn<Fields> = (data, opts) => {
return model.createMany(
data.map((data) => ({
...data,
createdAt: conn.fn.now(3),
updatedAt: conn.fn.now(3),
})),
opts
);
};

const update: UpdateFn<Fields> = (args) => {
return model.update({
...args,
Expand All @@ -116,6 +128,7 @@ export const defineSequelizeModel =
return {
...model,
create,
createMany,
update,
};
};

0 comments on commit 12b56f1

Please sign in to comment.