{"library":"masterrecord","title":"MasterRecord ORM","description":"MasterRecord is a lightweight, code-first Object-Relational Mapper (ORM) for Node.js, currently at version 1.0.4. It emphasizes a fluent, lambda-based query API, a comprehensive CLI-driven migration system, and out-of-the-box support for multiple relational databases including MySQL (5.7+/8.0+), PostgreSQL (9.6+/12+), and SQLite (3.x). The ORM operates on an Active Record pattern, providing entity serialization, lifecycle hooks, and built-in validation. A key differentiator is its \"ESM only\" nature, requiring Node.js 20+ and a host project configured as a module, with no CommonJS build available. It offers features like query result caching, bulk operations, and robust SQL injection protection through parameterized queries. The project seems to follow a stable release cadence with its initial major v1.0 release.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install masterrecord"],"cli":{"name":"masterrecord","version":null}},"imports":["import { MasterRecord } from 'masterrecord';","import { defineEntity } from 'masterrecord';","import { Entity } from 'masterrecord';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { MasterRecord } from 'masterrecord';\n\n// 1. Define an entity extending MasterRecord.Entity\nclass User extends MasterRecord.Entity {\n  id!: number;\n  name!: string;\n  email!: string;\n  age?: number;\n\n  static tableName = 'users'; // Explicitly define the table name\n\n  static fields = {\n    id: { type: 'number', primaryKey: true, autoIncrement: true },\n    name: { type: 'string', required: true, length: { min: 3, max: 255 } },\n    email: { type: 'string', required: true, pattern: /^\\S+@\\S+\\.\\S+$/, unique: true },\n    age: { type: 'number', required: false, min: 18 }\n  };\n}\n\nasync function runMasterRecord() {\n  // 2. Configure MasterRecord for SQLite database\n  await MasterRecord.configure({\n    connection: {\n      client: 'sqlite',\n      filename: './quickstart.sqlite'\n    },\n    entities: [User],\n    debug: process.env.NODE_ENV !== 'production' // Enable logging in development\n  });\n\n  // 3. Sync schema (for development; use migrations in production)\n  await MasterRecord.syncSchema();\n  console.log('Database schema synced successfully for User entity.');\n\n  // 4. Create a new user instance using the factory method\n  const newUser = MasterRecord.create(User, { \n    name: 'Alice Wonderland',\n    email: 'alice@example.com',\n    age: 28 \n  });\n  await newUser.save();\n  console.log('Created new user:', newUser.toObject());\n\n  // 5. Find a user by email\n  const foundUser = await MasterRecord.query(User).where(u => u.email === 'alice@example.com').first();\n  if (foundUser) {\n    console.log('Found user:', foundUser.toObject());\n    // 6. Update the user\n    foundUser.age = 29;\n    await foundUser.save();\n    console.log('Updated user age:', foundUser.toObject());\n  }\n\n  // 7. Disconnect from the database\n  await MasterRecord.disconnect();\n  console.log('MasterRecord disconnected.');\n}\n\nrunMasterRecord().catch(console.error);\n","lang":"typescript","description":"This quickstart demonstrates how to configure MasterRecord with an SQLite database, define a `User` entity, sync the schema, and perform basic CRUD operations (create, save, query) on entity instances.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}