{"id":16701,"library":"vr-models","title":"VR Models","description":"vr-models is a shared database models package specifically designed for VR applications. It leverages the Sequelize ORM, providing an abstraction layer for database interactions and ensuring data consistency across various VR projects. Shipping with comprehensive TypeScript types, it facilitates a type-safe development experience. The current stable version, 1.0.52, indicates an actively maintained package within its niche domain. While its release cadence isn't explicitly defined, the version number suggests ongoing development and refinement. Its primary differentiator is its specialized focus on the VR ecosystem, offering predefined model structures that might be common in VR development, and integrates with `vr-migrations` for robust schema management.","status":"active","version":"1.0.52","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","sequelize","models","typescript","vr","database"],"install":[{"cmd":"npm install vr-models","lang":"bash","label":"npm"},{"cmd":"yarn add vr-models","lang":"bash","label":"yarn"},{"cmd":"pnpm add vr-models","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core ORM functionality for database interaction.","package":"sequelize","optional":false},{"reason":"Provides database schema migration capabilities for VR models.","package":"vr-migrations","optional":false}],"imports":[{"note":"The package ships TypeScript types and is primarily designed for modern ESM usage. Avoid CommonJS `require`.","wrong":"const { initializeModels } = require('vr-models');","symbol":"initializeModels","correct":"import { initializeModels } from 'vr-models';"},{"note":"Individual models are typically named exports from the main package entry, not default exports from sub-paths.","wrong":"import VRUser from 'vr-models/VRUser';","symbol":"VRUser","correct":"import { VRUser } from 'vr-models';"},{"note":"Use `import type` for importing only type definitions to prevent bundling issues and improve tree-shaking.","wrong":"import { IVRUserAttributes } from 'vr-models';","symbol":"IVRUserAttributes","correct":"import type { IVRUserAttributes } from 'vr-models';"}],"quickstart":{"code":"import { Sequelize, DataTypes, Model } from 'sequelize';\nimport { initializeModels, VRUser, VRProduct } from 'vr-models';\n\ninterface Config { database: string; username?: string; password?: string; host?: string; dialect: string; storage?: string; }\n\nconst config: Config = {\n  dialect: 'sqlite',\n  storage: process.env.DB_STORAGE ?? './vr_database.sqlite',\n};\n\nconst sequelize = new Sequelize(config);\n\nasync function setupAndUseVRModels() {\n  try {\n    await sequelize.authenticate();\n    console.log('Database connection has been established successfully.');\n\n    // Initialize models from vr-models, passing the Sequelize instance\n    initializeModels(sequelize, DataTypes); // Assuming initializeModels takes sequelize and DataTypes\n\n    // Synchronize all models (in a real app, use migrations from vr-migrations)\n    await sequelize.sync({ alter: true });\n    console.log('All models were synchronized successfully.');\n\n    // Create a new VR user\n    const newUser = await VRUser.create({ username: 'playerOne', email: 'playerone@example.com' });\n    console.log('New VR user created:', newUser.toJSON());\n\n    // Create a new VR product\n    const newProduct = await VRProduct.create({ name: 'Virtual Headset', price: 299.99, description: 'High-fidelity VR experience.' });\n    console.log('New VR product created:', newProduct.toJSON());\n\n    // Find all VR users\n    const users = await VRUser.findAll();\n    console.log('All VR users:', users.map(u => u.toJSON()));\n\n  } catch (error) {\n    console.error('Unable to connect to the database or operate:', error);\n  } finally {\n    await sequelize.close();\n    console.log('Database connection closed.');\n  }\n}\n\nsetupAndUseVRModels();\n","lang":"typescript","description":"Demonstrates how to initialize Sequelize, import and synchronize models from `vr-models`, and perform basic CRUD operations with a sample VRUser and VRProduct model."},"warnings":[{"fix":"Review `vr-models` release notes for Sequelize v7 compatibility. Update `sequelize` imports to `@sequelize/core` and install specific dialect packages (e.g., `@sequelize/sqlite3`).","message":"Sequelize v7 introduces significant breaking changes, including renaming the main package to `@sequelize/core` and separating dialects into individual packages. If `vr-models` updates to Sequelize v7, this will require manual updates to your `sequelize` imports and dialect configurations.","severity":"breaking","affected_versions":">=2.0.0 (if upgrading to Sequelize v7)"},{"fix":"Audit your `sequelize` queries, especially those using `literal` and `replacements`, to ensure they are not negatively impacted. Avoid using quoted replacements in `literal` expressions.","message":"Sequelize v6.19.2 included a critical SQL injection fix that inadvertently introduced a breaking change related to how replacements were handled within raw SQL strings. While this prevents security vulnerabilities, it might break existing queries that relied on the old behavior of injecting quoted replacements.","severity":"breaking","affected_versions":">=6.19.2"},{"fix":"Ensure `vr-models` uses modern ES module `import` or CommonJS `require` statements for model definitions. Do not use `sequelize.import` in your own code when interacting with older `vr-models` versions if this was a pattern.","message":"The `sequelize.import` method for loading models was deprecated in Sequelize v5 and completely removed in v6. If `vr-models` or your consuming application uses older model loading patterns, it will break.","severity":"deprecated","affected_versions":"<6.0.0 (if `vr-models` depended on it internally or exposed it)"},{"fix":"Ensure consistent module syntax across your project. For `sequelize-cli`, consider renaming config files to `.cjs` or creating a local `package.json` with `\"type\": \"commonjs\"` in the `migrations` directory.","message":"Mixing ESM `import` syntax with CommonJS `require` in projects configured as ESM (e.g., `\"type\": \"module\"` in `package.json`) can lead to `ERR_REQUIRE_ESM` errors, particularly with `sequelize-cli` or older utility scripts that expect CJS.","severity":"gotcha","affected_versions":"All versions when using ESM-configured projects"},{"fix":"Increase the `max` option in your Sequelize connection pool configuration, optimize slow queries, ensure transactions are always committed or rolled back, and monitor database server load.","message":"Frequent `ConnectionAcquireTimeoutError` indicates that the Sequelize connection pool is exhausted, often due to too many concurrent requests, long-running queries, or uncommitted/unrolled-back transactions.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always align your installed `sequelize` version with the peer dependency specified by `vr-models` (e.g., `^6.x`). Check `npm install` warnings carefully.","message":"Incompatible versions of `sequelize` with `vr-models` (due to peer dependency mismatches) can lead to unexpected behavior, missing methods, or type errors, especially after major `sequelize` updates.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change `require()` calls to `import` statements or ensure that files intended to be CommonJS are named `.cjs` or reside in a package configured for CommonJS. For `sequelize-cli` migrations, consider adding `\"type\": \"commonjs\"` to a `package.json` within your `migrations` directory.","cause":"Attempting to `require()` an ES Module file, often when `\"type\": \"module\"` is set in `package.json`.","error":"ERR_REQUIRE_ESM: Must use import to load ES Module"},{"fix":"Adjust the `pool.max` and `pool.acquire` options in your Sequelize configuration. Investigate long-running queries or uncommitted transactions in your application logic.","cause":"The database connection pool is unable to acquire a connection within the specified timeout, often due to high load or unreleased connections.","error":"SequelizeConnectionAcquireTimeoutError: Operation timeout"},{"fix":"Ensure `initializeModels(sequelize, DataTypes)` is called correctly and that your Sequelize instance and `DataTypes` are correctly passed and available to all model definitions.","cause":"A Sequelize model was not properly initialized with the `init` method before being used, or the `sequelize` instance was not passed correctly during model setup.","error":"TypeError: Cannot read properties of undefined (reading 'init')"},{"fix":"Pass a `dialect` option to the `Sequelize` constructor, e.g., `new Sequelize({ dialect: 'sqlite', ... })`.","cause":"The database dialect (e.g., 'mysql', 'postgres', 'sqlite') was not provided in the Sequelize constructor options.","error":"ERROR: Dialect needs to be explicitly supplied as of v4.0.0"}],"ecosystem":"npm"}