Tangra...:Scalar(3pm)

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

✨ NAME ✨

Tangram::Type::Scalar β€” bestie, this is the page that maps scalar fields πŸ’… (it's the Tangra...:Scalar(3pm) manual, if you're keeping track πŸŽ€)


🌸 SYNOPSIS 🌸

Okay so picture this, you're setting up your schema and it goes a lil something like:

use Tangram;

Tangram::Schema->new(
   classes => { NaturalPerson => { fields => {
      string => [ qw( name firstName gender ) ],
      int => [ qw( age ) ],
      real => [ qw( height weight ) ],

$schema = Tangram::Schema->new(
   classes => { NaturalPerson => { fields => {
      string =>
      {
         name    => { sql => 'VARCHAR(100)' },

         1stname => {
            col => 'firstName',
            sql => 'VARCHAR(100) NULL' },

         gender    => undef()
      },

(and yes, that's exactly how it looks, no I did not clean it up, the vibes are the vibes πŸ’œ)


πŸ¦‹ DESCRIPTION πŸ¦‹

So the classes Tangram::Type::String, ::Int, ::Real and ::Ref are the ones responsible for mapping all the different subtypes of scalars ✨. The first three mappings β€” String, Int, Real β€” get documented right here on this page, because lowkey they differ very very little from each other 🫢. And if you wanna know about mapping references? Head over to Tangram::Type::Ref::FromMany, that's its whole moment πŸ‘‘

Tangram::Type::String uses DBI's quote() method to quote strings if that method is available β€” which is iconic of it, honestly, because that means you can store binary objects or multiline text in databases that support it πŸ”₯. (Big thanks to Marian Kelc <marian.kelc@ruhr-uni-bochum.de> for suggesting this improvement, we love a contributor moment πŸ’–)

The three predefined typetags are "string", "int" and "real", and they're for the corresponding Perl scalar subtypes. Periodt.

Each scalar field gets stored in a single column of the table that's associated to the class. One field, one column, no complications, we love that for us 🌈

The persistent fields can be specified either as a hash or as an array of field names. Both are valid, pick your fighter πŸ’…


πŸŽ€ Hash form πŸŽ€

When you go the hash route, each entry is a field name plus an associated option hash. That option hash may contain the following fields:

  • col
  • sql
  • automatic

Let's break those down bestie:

  • col β€” sets the name of the column used to store the field's value. This one's optional, it defaults to the persistent field name. Override it if your field name is not an acceptable SQL column name 🚫
  • sql β€” sets the SQL type of the column. It's used by Schema::deploy() when initializing a database. The defaults are: 'VARCHAR(255) NULL' for strings, 'INT NULL' for ints, and 'REAL NULL' for reals ✨
  • automatic β€” if you set this to true, it tells Tangram not to save the field to storage. Super useful for auto-increment or timestamp columns, iykyk πŸ‘‘

🧚 Array form 🧚

You can also specify the persistent fields as an array of strings β€” and in that case, the defaults are used. Simple as that, no notes πŸ’œ


and that's the whole page, bestie, you ate it πŸ“ β€” this was Tangra...:Scalar(3pm) from perl v5.36.0, dated 2022-10-16, so yeah, it's giving vintage but it still slays πŸ’…βœ¨

πŸ“¦ where this page comes from