Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/content/2.models/3.inserting-and-updating.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ You can also do this in a single command by using `create()` to create a new mod
const pet = await Pet.create({ name: "Zuko", type: "cat" });
```

## Bulk Inserting

Pass an array to `create()` to insert multiple records at once. The records are inserted with a single query, and an array of saved model instances is returned.

```ts
const pets = await Pet.create([
{ name: "Zuko", type: "cat" },
{ name: "Appa", type: "dog" },
]);
```

Default attributes and mutators are applied to each record, and the `saving`/`creating` events are dispatched for each model before the insert, followed by `created`/`saved` after.

You can also call `createMany()` directly, which always takes an array:

```ts
const pets = await Pet.createMany([
{ name: "Zuko", type: "cat" },
{ name: "Appa", type: "dog" },
]);
```

## Setting Attributes

You can set attributes directly on a model instance using property accessors and then save the model instance.
Expand Down
35 changes: 13 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vasta-orm",
"version": "0.0.14",
"version": "0.0.15",
"description": "Active record ORM built on top of Kysely",
"type": "module",
"author": "David Nahodyl <david.nahodyl@gmail.com>",
Expand All @@ -25,14 +25,8 @@
],
"exports": {
".": {
"import": {
"types": "./src/index.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./src/index.ts",
"default": "./dist/cjs/index.js"
}
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"scripts": {
Expand All @@ -42,9 +36,7 @@
"test:reset": "pnpm run db:reset && vitest run",
"test:watch": "vitest --typecheck",
"clean": "rm -rf dist/*",
"build": "pnpm run clean && (npm run build:esm & npm run build:cjs)",
"build:esm": "tsc -p tsconfig.json && tsc-alias -p tsconfig.json --resolve-full-paths --resolve-full-extension .js",
"build:cjs": "tsc -p tsconfig.cjs.json && tsc-alias -p tsconfig.cjs.json",
"build": "pnpm run clean && tsc -p tsconfig.json && tsc-alias -p tsconfig.json --resolve-full-paths --resolve-full-extension .js",
"generate:docs": "cd docs && pnpm run generate",
"db:reset": "kysely migrate:rollback --all && kysely migrate:latest && kysely seed:run",
"db:migrate": "kysely migrate:latest",
Expand All @@ -56,22 +48,21 @@
"format": "pnpm run fmt && pnpm run lint:fix",
"publish": "pnpm run build && npm publish --access public"
},
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "src/index.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"devDependencies": {
"@eslint/js": "^9.39.4",
"@types/node": "^24.12.4",
"@eslint/js": "^9.39.5",
"@types/node": "^24.13.3",
"@types/pg": "^8.20.0",
"eslint": "^10.3.0",
"eslint": "^10.7.0",
"eslint-config-prettier": "^9.1.2",
"kysely": "^0.29.0",
"kysely": "^0.29.3",
"kysely-ctl": "^0.21.0",
"oxfmt": "^0.51.0",
"pg": "^8.20.0",
"tsc-alias": "^1.8.17",
"pg": "^8.22.0",
"tsc-alias": "^1.9.1",
"typescript": "^5.9.3",
"typescript-eslint": "^8.59.3",
"typescript-eslint": "^8.64.0",
"vitest": "^1.6.1"
},
"peerDependencies": {
Expand Down
Loading
Loading