Name

QBit::Application::Model::DB::Table

Description

Base class for DB tables.

RO accessors

  • name

  • inherits

  • primary_key

  • indexes

  • foreign_keys

  • collate

  • engine

Abstract methods

  • create_sql

  • add_multi

  • add

  • delete

  • _get_field_object

  • _convert_fk_auto_type

Package methods

init

No arguments.

Method called from "new" before return object.

fields

No arguments.

Return values:

  • $fields - reference to array of objects (QBit::Application::Model::DB::Field)

Example:

  my $fields = $app->db->users->fields();

fields

No arguments.

Return values:

  • @field_names

Example:

  my @field_names = $app->db->users->field_names();

get_all

Arguments:

  • %opts - options with keys

    • comment

    • fields

    • filter

    • group_by

    • order_by

    • offset

    • limit

    • distinct

    • for_update

    • all_langs

For more information see QBit::Application::Model::DB::Query::get_all

Return values:

  • $data - reference to array

Example:

  my $data = $app->db->users->get_all(
      fields => [qw(id login)],
      filter => {id => 3},
  );

edit

Arguments:

  • $pkeys_or_filter - perl variables or object (QBit::Application::Model::DB::filter)

  • $data - reference to hash

Example:

  $app->db->users->edit(1, {login => 'LoginNew'});
  $app->db->users->edit([1], {login => 'LoginNew'});
  $app->db->users->edit({id => 1}, {login => 'LoginNew'});
  $app->db->users->edit($app->db->filter({login => 'Login'}), {login => 'LoginNew'});

get

Arguments:

  • $id - scalar or hash

  • %opts - options with keys

    • comment

    • fields

    • for_update

    • all_langs

For more information see QBit::Application::Model::DB::Query::get_all

Return values:

  • $data - reference to hash

Example:

  my $data = $app->db->users->get(3, fields => [qw(id login)],);

truncate

No arguments.

Truncate table.

Example:

  $app->db->users->truncate();

alter

Arguments:

  • %opts - options to alter

    • disable_keys

    • enable_keys

Example:

  $app->db->users->alter(disable_keys => TRUE);

  ...

  $app->db->users->alter(enable_keys => TRUE);

create

Create table in DB.

Arguments:

  • %opts - options with keys, same as for method create_sql

Example:

  $app->db->users->create();

drop

Arguments:

  • %opts - options with keys

    • if_exists - added 'IF EXISTS'

Example:

  $app->db->users->drop(); # DROP TABLE `users`;

  $app->db->users->drop(if_exists => TRUE); # DROP TABLE IF EXISTS `users`;

swap

Arguments:

  • $name_or_table - table name or object

Example:

  $app->db->users->swap('clients');

  # RENAME TABLE `users` TO `users_<pid>_<time>`, `clients` TO `users`, `users_<pid>_<time>` TO `clients`;

  $app->db->users->swap($app->db->clients); # same

default_fields

You can redefine this method in your Model.

default_primary_key

You can redefine this method in your Model.

default_indexes

You can redefine this method in your Model.

default_foreign_keys

You can redefine this method in your Model.

have_fields

Arguments:

  • $fields - reference to array

Return values:

  • $bool

Example:

  my $bool = $app->db->users->have_fields([qw(id login)]);

For more information see code and test.