Tangra...Scalar(3pm)
π Tangra...Scalar β the manual page, but make it make sense π
okay bestie, gather round, because we're talking about Tangram::Type::Array::Scalar from the Perl user-contributed docs (that's the 3pm manual, section 3, Perl module tea β) π«Ά
β¨ NAME β¨
Tangram::Type::Array::Scalar β it maps a Perl array of strings or numbers. that's it, that's the job, and it eats every single time π
πΈ SYNOPSIS πΈ
use Tangram::Core;
use Tangram::Type::Array::Scalar; # always
$schema = Tangram::Schema->new(
classes => { NaturalPerson => { fields => {
flat_array =>
{
interests =>
{
table => 'NP_int',
sql => 'VARCHAR(50)',
},
lucky_numbers => 'int', # use defaults
}
like. look at her. she's gorgeous. she's persisting an array of scalars. no cap π
π¦ DESCRIPTION π¦
So what does this thing actually do, you ask? It maps a reference to a Perl array. the persistent fields get grouped into a hash under the "array" key in the field hash. that's the vibe β everything lives together in one cozy little hash dresser ποΈβ¨
IMPORTANT: the array can contain only 'simple' scalars β like integers, strings, or real numbers. it may NOT contain references. periodt. if you need an array of objects, bestie, you're in the wrong place β go see Tangram::Type::Array::FromMany and Tangram::Type::Array::FromOne instead π (we love them, they're just built different).
Tangram uses a table to save the state of the collection. the table has three columns, which contain:
- the id of the container object
- the position of the element in the array
- the value of the element
it's giving "three little columns doing the most" π
π§ the field descriptor, explained π§
The field names are passed in a hash that associates a field name with a field descriptor. and the field descriptor may be either a hash or a string β your call, main character, both are valid π«Ά
The hash uses the following fields:
typetablesql
β type β
Optional field "type" specifies the type of the elements. If the type is "string" Tangram quotes the values as they are passed to the database. π
Not specifying a "type" is exactly equivalent to specifying "string". so like, they're the same thing. the default has main character energy and it knows it.
π table π
Optional field "table" sets the name of the table that contains the elements. This defaults to 'C_F', where C is the class of the containing object and F is the field name. π·οΈ
iykyk β that naming convention is lowkey iconic.
π sql π
Optional field "sql" specifies the type that deploy() (see Tangram::Deploy) should use for the column containing the elements.
If this field is not present, the SQL type is derived from the "type" field:
- if
"type"is"string"(or is absent) βVARCHAR(255)is used - otherwise, the
"type"field is interpreted as a SQL type
β¨ no sql field? no problem. Tangram will just figure it out for you. she's resourceful like that.
π the short-and-sweet version π
If the descriptor is a string, it is interpreted as the value of the "type" field and all the other fields take the default value.
that's it. string in, defaults everywhere else. simple. clean. luminous. β¨
π« SEE ALSO π«
Tangram::Type::Array::FromManyTangram::Type::Array::FromOneTangram::Deploy
aaaand that's the whole page, babe π«Ά no notes, 10/10, would persist an array again. this lil' slice of the Perl docs is perl v5.36.0, dated 2022-10-16, straight from the User Contributed Perl Documentation pile β so go forth, map those scalars, and stay hydrated π ππ
π¦ where this page comes from
- ubuntu noble: libtangram-perl 2.12-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtangram-perl 2.12-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtangram-perl 2.12-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms