Skip to content

Custom Generators

SqlProof maps PostgreSQL types to fast-check arbitraries automatically. For tighter control — realistic emails, specific numeric ranges, domain-constrained strings — override them via proof.customize().

Basic Override

import fc from 'fast-check';
proof.customize('products', {
price: fc.float({ min: 0.01, max: 9999.99, noNaN: true }),
name: fc.string({ minLength: 1, maxLength: 100 }),
});

Common Patterns

Numeric ranges

proof.customize('products', {
price: fc.float({ min: 0.01, max: 9999.99, noNaN: true }),
stock: fc.integer({ min: 0, max: 10000 }),
discount_pct: fc.float({ min: 0, max: 0.5, noNaN: true }),
});

Constrained strings

proof.customize('customers', {
email: fc.emailAddress(),
name: fc.string({ minLength: 2, maxLength: 100 }),
});

Picking from a fixed set

proof.customize('orders', {
currency: fc.constantFrom('USD', 'EUR', 'GBP'),
region: fc.constantFrom('us-east', 'us-west', 'eu-central'),
});

Dates in a specific range

proof.customize('orders', {
created_at: fc.date({
min: new Date('2020-01-01'),
max: new Date('2024-12-31'),
noInvalidDate: true,
}),
});

Default Type Mappings

PostgreSQL TypeDefault Arbitrary
integer, int4fc.integer({ min: -2147483648, max: 2147483647 })
bigintfc.bigInt()
smallintfc.integer({ min: -32768, max: 32767 })
numeric(p,s), decimalfc.float() scaled to precision
real, float4fc.float({ noNaN: true, noDefaultInfinity: true })
double precisionfc.double({ noNaN: true, noDefaultInfinity: true })
booleanfc.boolean()
textfc.string({ unit: 'grapheme', maxLength: 255 })
varchar(n)fc.string({ unit: 'grapheme', maxLength: n })
uuidfc.uuid()
timestamp, timestamptzfc.date({ noInvalidDate: true }) clamped to 1970–2099
datefc.date() formatted as YYYY-MM-DD
json, jsonbfc.jsonValue()
enum typesfc.constantFrom(...enumValues)
integer[], etc.fc.array() of base type