{"id":42210,"library":"vasta-orm","title":"Vasta ORM","description":"Vasta is a type-safe Active Record ORM for TypeScript, built on top of Kysely (v0.29+). It provides a Laravel Eloquent-inspired interface for defining models with relationships, attributes, and lifecycle hooks, while leveraging Kysely's SQL query builder for raw performance. Version 0.0.14 is the latest stable, with an active development cadence (weekly releases). Key differentiators: full TypeScript type safety via Kysely's types, active record pattern with instance-based saves, and support for eloquent-style relationships (hasOne, hasMany, belongsTo) without sacrificing the ability to drop down to raw SQL via Kysely.","status":"active","version":"0.0.14","language":"javascript","source_language":"en","source_url":"https://github.com/Smef/vasta","tags":["javascript","orm","kysely","typescript","active record"],"install":[{"cmd":"npm install vasta-orm","lang":"bash","label":"npm"},{"cmd":"yarn add vasta-orm","lang":"bash","label":"yarn"},{"cmd":"pnpm add vasta-orm","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: Vasta uses Kysely as its underlying query builder and database interface","package":"kysely","optional":false}],"imports":[{"note":"Model is a named export; default export is not provided.","wrong":"import Model from 'vasta-orm'","symbol":"Model","correct":"import { Model } from 'vasta-orm'"},{"note":"Vasta models are typically defined as classes extending Model and exported as named exports. Use ESM imports for type safety.","wrong":"const Pet = require('./models/Pet')","symbol":"Pet","correct":"import { Pet } from './models/Pet'"},{"note":"Relation classes are exported from a subpath 'vasta-orm/relations' to avoid polluting the main module.","wrong":"import { HasManyRelation } from 'vasta-orm'","symbol":"HasManyRelation","correct":"import { HasManyRelation } from 'vasta-orm/relations'"}],"quickstart":{"code":"import { Model } from 'vasta-orm';\nimport { Kysely, PostgresDialect } from 'kysely';\nimport { Pool } from 'pg';\n\n// Define your database type (optional but recommended)\ninterface Database {\n  pets: PetsTable;\n  owners: OwnersTable;\n}\n\ninterface PetsTable {\n  id: number;\n  name: string;\n  owner_id: number;\n  species: string;\n}\n\ninterface OwnersTable {\n  id: number;\n  name: string;\n}\n\n// Create Kysely instance\nconst db = new Kysely<Database>({\n  dialect: new PostgresDialect({\n    pool: new Pool({\n      connectionString: process.env.DATABASE_URL ?? 'postgres://localhost/mydb',\n    }),\n  }),\n});\n\n// Define your model\nexport class Pet extends Model<Pet, PetsTable> {\n  static tableName = 'pets';\n  static primaryKey = 'id';\n  static timestamps = true;\n\n  // define relationships\n  owner() {\n    return this.belongsTo<Owner>('owners', 'owner_id');\n  }\n}\n\n// Use the model\nasync function main() {\n  const pet = await Pet.findOrFail(1);\n  pet.name = 'Fluffy';\n  await pet.save();\n\n  const owner = await pet.owner().fetch();\n  console.log(owner.name);\n}\n\nmain().catch(console.error);","lang":"typescript","description":"Shows defining a Pet model extending Model, setting up Kysely with PostgreSQL, querying a record, modifying it, saving, and accessing a relationship."},"warnings":[{"fix":"Install kysely@^0.29.0 via npm install kysely@^0.29.0","message":"Vasta requires Kysely v0.29.0 or higher; using an older Kysely version will cause runtime errors.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use explicit relationship methods like this.hasMany(RelatedModel, foreignKey) instead of this.relation('hasMany', ...).","message":"The 'relation' method on Model is deprecated in favor of specific relationship methods (hasMany, belongsTo, etc.)","severity":"deprecated","affected_versions":"<0.1.0"},{"fix":"Update Model instantiation: new Model(db, attributes) or use Model.findOrFail(db, id).","message":"In v0.0.10, the Model constructor signature changed: you must now pass the database instance as the first argument.","severity":"breaking","affected_versions":">=0.0.10"},{"fix":"Define an interface for your table and pass it as the second generic parameter.","message":"When using TypeScript strict mode, you must provide generic type arguments to Model (e.g., Model<ModelClass, TableInterface>) or you'll get implicit any errors.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"For now, set static timestamps = true. Monitor changelog for changes.","message":"The 'timestamps' property is currently boolean; in future versions it may become an object configuration.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"For atomic operations, wrap multiple saves in a Kysely transaction and pass the transaction object to Vasta methods if supported (check docs).","message":"Vasta does not automatically handle transactions; each save() call runs in its own implicit transaction if Kysely's dialect supports it.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.0.14':48 'abil':91 'activ':9,55,70,104 'attribut':33 'base':76 'belongsto':87 'builder':43 'built':14 'cadenc':57 'defin':29 'develop':56 'differenti':61 'drop':93 'eloqu':25,82 'eloquent-inspir':24 'eloquent-styl':81 'full':62 'hasmani':86 'hason':85 'hook':36 'inspir':26 'instanc':75 'instance-bas':74 'interfac':27 'javascript':100 'key':60 'kyse':18,39,67,99,102 'laravel':23 'latest':51 'leverag':38 'lifecycl':35 'model':30 'orm':2,11,101 'pattern':72 'perform':46 'provid':21 'queri':42 'raw':45,96 'record':10,71,105 'relationship':32,84 'releas':59 'sacrif':89 'safe':8 'safeti':65 'save':77 'sql':41,97 'stabl':52 'style':83 'support':79 'top':16 'type':7,64,69 'type-saf':6 'typescript':13,63,103 'v0.29':19 'vasta':1,3 'version':47 'via':66,98 'week':58 'without':88","created_at":"2026-06-04T18:56:09.254165+00:00","updated_at":"2026-06-04T18:56:09.254165+00:00","problems":[{"fix":"Use named import: import { Model } from 'vasta-orm'","cause":"Importing Model incorrectly (e.g., using default import) causing Model to be undefined.","error":"TypeError: Class extends value undefined is not a constructor or null"},{"fix":"Call Model.setDb(kyselyInstance) before any model operations, or pass db to constructor.","cause":"Trying to use a model without setting up Kysely database instance.","error":"Error: Kysely instance is required. Use Model.setDb(kyselyInstance) or pass it when constructing models."},{"fix":"Run npm install vasta-orm and ensure tsconfig.json has 'moduleResolution': 'node' or 'bundler'.","cause":"Missing package installation or incorrect import path.","error":"Cannot find module 'vasta-orm' or its corresponding type declarations."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://vastajs.com/","github":"https://github.com/Smef/vasta","docs":null,"changelog":null,"pypi":null,"npm":"vasta-orm","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}