Mock::Data::Plugin::SQLTypes - Collection of generators that produce data matching a SQL column type
my $mock= Mock::Data->new(['SQL']); $mock->integer(11); $mock->sequence($seq_name); $mock->numeric([9,2]); $mock->float({ bits => 32 }); $mock->bit; $mock->boolean; $mock->varchar(16); $mock->char(16); $mock->text(256); $mock->blob(1000); $mock->varbinary(32); $mock->datetime({ after => '1900-01-01', before => '1990-01-01' }); $mock->date; $mock->uuid; $mock->json({ data => $data || {} }); $mock->inet; $mock->cidr; $mock->macaddr;
This module defines generators that match the data type names used by various relational databases.
The output patterns are likely to change in future versions, but will always be valid for inserting into a column of that type.
my $generatpr= generator_for_type($sqltype);
Return a generator which can generate valid strings for a given SQL type.
(all generators are also exportable)
See "integer" in Mock::Data::Plugin::Number
Alias for integer({ bits => 8 }).
integer({ bits => 8 })
Alias for integer({ bits => 16 }).
integer({ bits => 16 })
Alias for integer({ bits => 63 }).
integer({ bits => 63 })
See "sequence" in Mock::Data::Plugin::Number
Alias for sequence
See "decimal" in Mock::Data::Plugin::Numeric
Alias for decimal.
decimal
See "float" in Mock::Data::Plugin::Numeric
Aliases for float({ size => 7 })
float({ size => 7 })
Aliases for float({ size => 15 })
float({ size => 15 })
Return a 0 or a 1
Alias for bit. While postgres prefers 'true' and 'false', it allows 0/1 and they are more convenient to use in Perl.
bit
'true'
'false'
$str= $mock->varchar($size); $str= $mock->varchar(\%options, $size); # %options: { size => $max_chars, size_weight => sub($size) { ... } source => $generator_or_name, }
Generate a string of random length, from 1 to $size characters. If $size is not given, it defaults to 16. size_weight is a function used to control the distribution of random lengths. The default applies a reduced chance of generating long strings when $size is greater than 32.
$size
size_weight
source is the name of a generator (or a generator reference) to use for generating words that get concatenated up to the random length. The default is the generator named 'word' in the current Mock::Data, and if that doesn't exist it uses "word" in Mock::Data::Plugin::Text.
source
'word'
Mock::Data
Alias for varchar
varchar
Same as varchar, but the default size is 256.
Aliases for text, and don't generate larger data because that would just slow things down.
text
$str= $mock->char($size); $str= $mock->char(\%options, $size);
Same as varchar, but the default size is 1, and the string will be padded with whitespace up to $size.
$datestr= $mock->datetime(); $datestr= $mock->datetime({ before => $date, after => $date });
Returns a random date from a date range, defaulting to the past 10 years. The input and output date strings must all be in ISO-8601 format, or an object that stringifies to that format. The output does not have the 'T' in the middle or 'Z' at the end, for widest compatibility with being able to insert into databases.
Like datetime, but only the 'YYYY-MM-DD' portion.
datetime
'YYYY-MM-DD'
Alias for datetime.
Aliases for blob. None of these change the default string length, because longer strings of data would just slow things down.
blob
See "uuid" in Mock::Data::Plugin::Numeric
Return '{}'. This is just the minimal valid value that makes it most likely that you can perform operations on the column without type errors.
See "ipv4" in Mock::Data::Plugin::Net
See "cidr" in Mock::Data::Plugin::Net
See "macaddr" in Mock::Data::Plugin::Net
Michael Conrad <mike@nrdvana.net>
version 0.03
This software is copyright (c) 2021 by Michael Conrad.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Mock::Data, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mock::Data
CPAN shell
perl -MCPAN -e shell install Mock::Data
For more information on module installation, please visit the detailed CPAN module installation guide.