VR Models

1.0.52 · active · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize Sequelize, import and synchronize models from `vr-models`, and perform basic CRUD operations with a sample VRUser and VRProduct model.

import { Sequelize, DataTypes, Model } from 'sequelize';
import { initializeModels, VRUser, VRProduct } from 'vr-models';

interface Config { database: string; username?: string; password?: string; host?: string; dialect: string; storage?: string; }

const config: Config = {
  dialect: 'sqlite',
  storage: process.env.DB_STORAGE ?? './vr_database.sqlite',
};

const sequelize = new Sequelize(config);

async function setupAndUseVRModels() {
  try {
    await sequelize.authenticate();
    console.log('Database connection has been established successfully.');

    // Initialize models from vr-models, passing the Sequelize instance
    initializeModels(sequelize, DataTypes); // Assuming initializeModels takes sequelize and DataTypes

    // Synchronize all models (in a real app, use migrations from vr-migrations)
    await sequelize.sync({ alter: true });
    console.log('All models were synchronized successfully.');

    // Create a new VR user
    const newUser = await VRUser.create({ username: 'playerOne', email: 'playerone@example.com' });
    console.log('New VR user created:', newUser.toJSON());

    // Create a new VR product
    const newProduct = await VRProduct.create({ name: 'Virtual Headset', price: 299.99, description: 'High-fidelity VR experience.' });
    console.log('New VR product created:', newProduct.toJSON());

    // Find all VR users
    const users = await VRUser.findAll();
    console.log('All VR users:', users.map(u => u.toJSON()));

  } catch (error) {
    console.error('Unable to connect to the database or operate:', error);
  } finally {
    await sequelize.close();
    console.log('Database connection closed.');
  }
}

setupAndUseVRModels();

view raw JSON →