Tangra...Scalar(3pm)

πŸ“¦
version 2.12 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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:

  • type
  • table
  • sql

⭐ 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::FromMany
  • Tangram::Type::Array::FromOne
  • Tangram::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