{"id":41683,"library":"orchid-orm-test-factory","title":"Orchid ORM Test Factory","description":"Orchid ORM Test Factory is a companion library for Orchid ORM that simplifies creating mock data for tests. Version 1.0.130 is the current stable release, updated regularly alongside Orchid ORM. It uses @faker-js/faker for generating realistic fake data and provides a declarative API to define factories for database models. Unlike generic factories, it integrates directly with Orchid ORM's model layers, supporting associations, custom column types, and lifecycle hooks. The factory is type-safe, fully typed with TypeScript, and designed for seamless use in integration or unit tests.","status":"active","version":"1.0.130","language":"javascript","source_language":"en","source_url":"https://github.com/romeerez/orchid-orm","tags":["javascript","factory","orchid-orm","test","typescript"],"install":[{"cmd":"npm install orchid-orm-test-factory","lang":"bash","label":"npm"},{"cmd":"yarn add orchid-orm-test-factory","lang":"bash","label":"yarn"},{"cmd":"pnpm add orchid-orm-test-factory","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Generates fake data for factory attributes.","package":"@faker-js/faker","optional":false}],"imports":[{"note":"Named export, not default. TypeScript types are included.","wrong":"import factory from 'orchid-orm-test-factory'","symbol":"factory","correct":"import { factory } from 'orchid-orm-test-factory'"},{"note":"Case-sensitive: 'defineFactory' is lowercase d. Used to define a factory for a model.","wrong":"import { DefineFactory } from 'orchid-orm-test-factory'","symbol":"defineFactory","correct":"import { defineFactory } from 'orchid-orm-test-factory'"},{"note":"Type import for passing factory or callback. Also import 'factory' type for the return type.","wrong":null,"symbol":"FactoryOrCallback","correct":"import { FactoryOrCallback } from 'orchid-orm-test-factory'"}],"quickstart":{"code":"import { factory, defineFactory } from 'orchid-orm-test-factory';\nimport { db } from './db'; // your Orchid ORM db instance\nimport { faker } from '@faker-js/faker';\n\n// Define a factory for a User model\nconst userFactory = defineFactory(db.user, (f) => ({\n  name: faker.person.fullName(),\n  email: faker.internet.email(),\n  age: faker.number.int({ min: 18, max: 99 }),\n}));\n\n// Build a user object without persisting\nconst userData = await userFactory.build();\nconsole.log(userData);\n\n// Create a user in the database\nconst user = await userFactory.create();\nconsole.log(user);\n\n// Create multiple users\nconst users = await userFactory.createList(5);\nconsole.log(users);\n\n// Override attributes\nconst customUser = await userFactory.create({ name: 'Alice' });\nconsole.log(customUser);","lang":"typescript","description":"Shows how to define a factory for a User model, build an object without persisting, create a single record, create multiple records, and override attributes."},"warnings":[{"fix":"Ensure the factory callback returns a synchronous object. If async data is needed, precompute it outside the factory.","message":"Factory functions must return a plain object, not an async function or promise. Async callbacks cause undefined attribute values.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use 'db.user' (where 'db' is your Orchid ORM instance) instead of a plain 'user' object.","message":"The 'defineFactory' function must be called with a model from your Orchid ORM db instance, not with a table name string or raw query builder.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefer using the 'f' parameter passed to the callback (currently undocumented).","message":"Using 'faker' directly inside factory callbacks may conflict with future versions if faker is removed as a dependency. The library wraps faker behind the scenes.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Change 'import orchidFactory from 'orchid-orm-test-factory'' to 'import { factory } from 'orchid-orm-test-factory''.","message":"In version 0.x, factory was a default export. In 1.0.0, it changed to a named export.","severity":"breaking","affected_versions":"1.0.0"}],"env_vars":null,"search_vec":"'/faker':40 '1.0.130':24 'alongsid':32 'api':50 'associ':70 'column':72 'companion':11 'creat':18 'current':27 'custom':71 'data':20,45 'databas':55 'declar':49 'defin':52 'design':88 'direct':62 'factori':4,8,53,59,78,98 'fake':44 'faker':38 'faker-j':37 'fulli':83 'generat':42 'generic':58 'hook':76 'integr':61,93 'javascript':97 'js':39 'layer':68 'librari':12 'lifecycl':75 'mock':19 'model':56,67 'orchid':1,5,14,33,64,100 'orchid-orm':99 'orm':2,6,15,34,65,101 'provid':47 'realist':43 'regular':31 'releas':29 'safe':82 'seamless':90 'simplifi':17 'stabl':28 'support':69 'test':3,7,22,96,102 'type':73,81,84 'type-saf':80 'typescript':86,103 'unit':95 'unlik':57 'updat':30 'use':36,91 'version':23","created_at":"2026-06-04T18:53:36.452407+00:00","updated_at":"2026-06-04T18:53:36.452407+00:00","problems":[{"fix":"Run 'npm install orchid-orm-test-factory @faker-js/faker'.","cause":"Package not installed or missing peer dependency '@faker-js/faker'.","error":"Error: Cannot find module 'orchid-orm-test-factory'"},{"fix":"Ensure 'db' is your Orchid ORM database instance and 'user' is a defined model.","cause":"Passing a non-model object; 'db.user' must be an Orchid ORM model, not a raw table or query builder.","error":"TypeError: db.user is not a function"}],"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://orchid-orm.netlify.app/guide/orm-test-factories.html","github":"https://github.com/romeerez/orchid-orm","docs":null,"changelog":null,"pypi":null,"npm":"orchid-orm-test-factory","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"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}}