Skip to main content

Create Records

You can build a record using BaseModel#constructor or BaseModel.build.

const user1 = new User();
user1.name = 'John Doe';
user1.age = 27;

const user2 = new User({ name: 'John Doe', age: 27 });

const user3 = User.build({ name: 'John Doe', age: 27 });

Then call BaseModel#save to make it persistent.

await user1.save();

BaseModel.create builds and saves at once.

const user4 = await User.create({ name: 'John Doe', age: 27 });

BaseModel.createBulk creates multiple records at once.

const users = await User.createBulk([
{ name: 'John Doe', age: 27 },
{ name: 'Bill Smith', age: 45 },
{ name: 'Alice Jackson', age: 27 },
]);