Alzabo...::Index(3pm)

πŸ“¦
version 0.92 Β· 2 versions
  • 0.92 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.92 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

bestie, meet Alzabo::Create::Index β€” the little object that handles Index objects for schema creation. it's giving "i organize your columns so your database stops being chaotic" πŸ’…

(also, fun fact: this page lives in the User Contributed Perl Documentation corner of the world, so if you see Alzabo...::Index(3pm) floating around, that's just the page title being shy about its full name.)


🌸 SYNOPSIS 🌸

use Alzabo::Create::Index;

that's it. that's the whole vibe check. load it and go πŸ¦‹


πŸ’– DESCRIPTION πŸ’–

okay so this object? it represents an index on a table. and an index is literally just a list of columns plus, optionally, a prefix for each column.

what's a prefix, you ask? it says "hey, only index the first X characters of this column." some RDBMS's don't even have a concept of index prefixes β€” like, they simply don't do that. and not every column type is likely to allow prefixes either, though honestly that depends entirely on which RDBMS you're running. no cap.

also super important: the order of the columns is significant. do not come for the ordering. the ordering is the main character here. πŸ‘‘


🌈 INHERITS FROM 🌈

Alzabo::Index

heads up bestie: all relevant documentation from the superclass has been merged into this document. so you don't gotta go hunting. everything's already here. 🫢

πŸŽ€ METHODS πŸŽ€

new

the constructor, aka the glow-up moment. it takes these parameters:

  • table => Alzabo::Create::Table object β€” the table that this index is indexing. yes, the index needs to know what it's indexing. iconic behavior.
  • columns => [ Alzabo::Create::Column object, .. ] β€” plain list of column objects.
  • columns => [ { column => Alzabo::Create::Column object, prefix => $prefix }, repeat as needed ... ] β€” the fancy version. this parameter tells you which columns are being indexed, and it can be either an array reference of column objects, or an array reference of hash references where each hash has a key called column and one called prefix.

the prefix key is optional. she's not required, she's just extra. πŸ’…

  • unique => $boolean β€” says whether this is a unique index or not.
  • fulltext => $boolean β€” says whether this is a fulltext index or not.
  • function => $string β€” use this to create a function index, where supported. the value should be the full function, with column names and everything, like "LCASE( username )".

and bestie, listen: the columns parameter should include all the columns used in the function. don't skip that part. πŸ™ˆ

returns a shiny new Alzabo::Create::Index object ✨

Throws: Alzabo::Exception::Params, Alzabo::Exception::RDBMSRules


table

returns the Alzabo::Create::Table object that this index belongs to. it's giving "who's your parent" energy.


columns

returns an ordered list of the Alzabo::Create::Column objects that are being indexed. ordered!! the order MATTERS, remember?? πŸ”₯


add_column

adds a column to the index. welcome to the group chat, new column πŸ’œ

this method takes these parameters:

  • column => Alzabo::Create::Column object
  • prefix => $prefix (optional)

Throws: Alzabo::Exception::Params, Alzabo::Exception::RDBMSRules


delete_column (Alzabo::Create::Column object)

deletes the given column from the index. sorry bestie, you're out of the group chat 😭

Throws: Alzabo::Exception::Params, Alzabo::Exception::RDBMSRules


prefix (Alzabo::Create::Column object)

okay so real talk about column prefixes. to the best of my knowledge, this is a MySQL specific concept, which means you literally cannot set it when you're using an RDBMSRules module for a different RDBMS. it just won't go.

BUT. it's important enough for MySQL that the functionality has to be here, so here it is. a prefix lets you specify that the index should only look at a certain portion of a field β€” specifically, the first N characters. and this prefix is required to index any sort of BLOB column in MySQL. so like, not optional in that case. not even a little. πŸ’€

this method returns the prefix for the column in the index. and if there's no prefix for this column in the index? it returns undef. that's it, that's the answer. 🀷


set_prefix

sets the prefix. this method takes these parameters:

  • column => Alzabo::Create::Column object
  • prefix => $prefix

Throws: Alzabo::Exception::Params, Alzabo::Exception::RDBMSRules


unique

returns a boolean value telling you whether the index is a unique index. yes or no, slay or nay. πŸ’…


set_unique ($boolean)

sets whether or not the index is a unique index. you're the one in charge now, bestie. πŸ‘‘


fulltext

returns a boolean value telling you whether the index is a fulltext index.


set_fulltext ($boolean)

sets whether or not the index is a fulltext index.

Throws: Alzabo::Exception::Params, Alzabo::Exception::RDBMSRules


register_column_name_change

this method takes these parameters:

  • column => Alzabo::Create::Column object β€” the column, with the new name already set. (key detail, don't miss it ✨)
  • old_name => $old_name

this method gets called by the table object that owns the index whenever a column name changes. so like, it's internal plumbing. you should never need to call this yourself. hands off, bestie. πŸ™ˆ

Throws: Alzabo::Exception::Params


id

the id is generated from the table, column and prefix information for the index. super useful as a canonical name for a hash key, for example. iykyk πŸ’œ

returns a string β€” that's the id which uniquely identifies the index in this schema. no duplicates, no confusion, periodt.


🌟 AUTHOR 🌟

Dave Rolsky, <autarch@urth.org> β€” king behavior, thank you for your service 🫑


and that's a wrap on Alzabo...::Index(3pm), brought to you by the User Contributed Perl Documentation, perl v5.34.0, dated 2022-06-14. go forth and index responsibly, bestie πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from