Git Product home page Git Product logo

dbix-class-helper-resultset-mysqlhacks's Introduction

NAME

DBIx::Class::Helper::ResultSet::MySQLHacks - Useful MySQL-specific operations for DBIx::Class

VERSION

version v1.0.0

SYNOPSIS

# Your base resultset
package MySchema::ResultSet;

use strict;
use warnings;

use parent 'DBIx::Class::ResultSet';

__PACKAGE__->load_components('Helper::ResultSet::MySQLHacks');

# In other resultset classes
package MySchema::ResultSet::Bar;

use strict;
use warnings;

use parent 'MySchema::ResultSet';

# In code using the resultset
$rs->multi_table_delete(qw< rel1 rel2 >);
$rs->multi_table_update(\%values);

DESCRIPTION

This MySQL-specific ResultSet helper contains a series of hacks for various SQL operations that only work for MySQL. These hacks are exactly that, so it's possible that the SQL manipulation isn't as clean as it should be.

METHODS

multi_table_delete

my $underlying_storage_rv = $rs->multi_table_delete;  # deletes rows from the current table
my $underlying_storage_rv = $rs->multi_table_delete(qw< rel1 rel2 >);

Runs a delete using the multiple table syntax, which supports join operations. This is useful in cases with a joined ResultSet that require rows to be deleted, and using "delete_all" in DBIx::Class::ResultSet would be too slow.

Without arguments, it will delete rows from the current table, ie: "current_source_alias" in DBIx::Class::ResultSet. Otherwise, it can take a list of relationships to delete from. These must be existing relationship aliases tied to the joins, not table names.

This method works by taking a count ResultSet, removing the SELECT COUNT(*) portion, and splicing in the DELETE @aliases part.

The return value is a pass through of what the underlying storage backend returned, and may vary. See "execute" in DBI for the most common case.

NOTE: This method will not delete from views, per MySQL limitations.

multi_table_update

my $underlying_storage_rv = $rs->multi_table_update(\%values);

Runs a update using the multiple table syntax, which supports join operations. This is useful in cases with a joined ResultSet that require rows to be updated, and using "update_all" in DBIx::Class::ResultSet would be too slow.

A values hashref is required. It's highly recommended that the keys are named as alias.column pairs, since multiple tables are involved.

This method works by acquiring the FROM, SET, and WHERE clauses separately and merging them back into a proper multi-table UPDATE query.

The return value is a pass through of what the underlying storage backend returned, and may vary. See "execute" in DBI for the most common case.

dbh_execute

my $rv                = $rs->dbh_execute($sql, $bind);
my ($rv, $sth, @bind) = $rs->dbh_execute($sql, $bind);

Sends any SQL statement to the $dbh via "dbh_do" in DBIx::Class::Storage::DBI while running the usual query loggers and re-connection protections that come with DBIC.

This runs code similar to DBIx::Class::Storage::DBI's _execute method, except that it takes SQL and binds as input. Like _dbh_execute and _execute, it returns different outputs, depending on the context.

AUTHOR

Grant Street Group [email protected]

COPYRIGHT AND LICENSE

This software is Copyright (c) 2021 by Grant Street Group.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

dbix-class-helper-resultset-mysqlhacks's People

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.