Questions tagged [dbix-class]

DBIx::Class is a Perl object-relational mapping (ORM) module. It aims to make representing queries in your code as perl-ish as possible while still providing access to as many of the capabilities of the database as possible, including retrieving related records from multiple tables in a single query, JOIN, LEFT JOIN, COUNT, DISTINCT, GROUP BY, ORDER BY and HAVING support.

from the description on CPAN:

This is an SQL to OO mapper with an object API inspired by Class::DBI (with a compatibility layer as a springboard for porting) and a resultset API that allows abstract encapsulation of database operations. It aims to make representing queries in your code as perl-ish as possible while still providing access to as many of the capabilities of the database as possible, including retrieving related records from multiple tables in a single query, JOIN, LEFT JOIN, COUNT, DISTINCT, GROUP BY, ORDER BY and HAVING support.

DBIx::Class can handle multi-column primary and foreign keys, complex queries and database-level paging, and does its best to only query the database in order to return something you've directly asked for. If a resultset is used as an iterator it only fetches rows off the statement handle as requested in order to minimise memory usage. It has auto-increment support for SQLite, MySQL, PostgreSQL, Oracle, SQL Server and DB2 and is known to be used in production on at least the first four, and is fork- and thread-safe out of the box (although your DBD may not be).

377 questions
7
votes
1 answer

How should I set up my DBIx::Class result classes in this simple case?

Let's suppose I have a the following simplified example database consisting of three tables: CREATE TABLE people ( person_id INTEGER PRIMARY KEY, person_name VARCHAR(100) ); CREATE TABLE events ( event_id INTEGER PRIMARY KEY, …
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
7
votes
2 answers

How to setup a DBIx::Class schema with Moose -- the definite guide

I found it rather difficult to find information about how to assemble a DBIx::Class schema structure using Moose. How to do that correctly (essentially working) and in modern Perl (good style, fast, without warnings)? These are my goals: follow…
Daniel Böhmer
  • 14,463
  • 5
  • 36
  • 46
7
votes
3 answers

Passing CAST(foo AS type) as a relationship condition in DBIx::Class

For historical reasons, we have a table at work that has integer values in a text field that correspond to the ID's in another table. Example: CREATE TABLE things ( id INTEGER, name VARCHAR, thingy VARCHAR ); CREATE TABLE…
Aurelia Peters
  • 2,169
  • 1
  • 20
  • 34
7
votes
3 answers

DBIx and inheritance in Perl

I'm currently trying to implement the following scenario with DBIx: The table products contains "general products" and "bundle products" (bundle products are collections of general products): package Product; use base…
6
votes
2 answers

How do I prevent DBIx::Class::Schema::Loader from automatically adding InflateColumn::DateTime in Catalyst?

I am using Catalyst and DBIx::Class::Schema::Loader to create my model in Catalyst like so: script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=static overwrite_modifications=1 components=EncodedColumn dbi:mysql:mydb mydb…
Rob Boerman
  • 2,148
  • 14
  • 21
6
votes
2 answers

How can I pretty print DBIx::Class results?

I'd like to pretty-print DBIx::Class::ResultSet results like this: my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db'); my $rs = $schema->resultset('Track')->all() # then print $rs with all of those feilds I found…
Soid
  • 2,585
  • 1
  • 30
  • 42
6
votes
2 answers

How to increment a column using DBIx::Class?

I'm trying to convert some raw DBI calls to DBIx::Class. I occasionally run across something like: UPDATE 'foo' SET bar = bar + 1 WHERE ... Is there way to do have DBIx::Class execute exactly this kind of query? I don't want to do something…
oalders
  • 5,239
  • 2
  • 23
  • 34
6
votes
1 answer

DBIx:Class - cannot find source for model

I am trying to use DBIx:Class. I have successfully created the Schema class using DBIx:class::Schema::Loader. I can also connect to the database. #!/usr/bin/perl -w use Test::More tests => 5; use_ok('Models::ModelRole'); use_ok('Models::User'); my…
Luke
  • 1,768
  • 2
  • 20
  • 30
6
votes
1 answer

Prefetch related row or nothing with DBIx::Class, maybe with OUTER LEFT JOIN?

I want to retrieve rows from a table with DBIx::Class and prefetch respective rows from the same table where a column has a particular other value. I need to fetch all assignments from schedule A (to copy them) and retrieve all respective…
Daniel Böhmer
  • 14,463
  • 5
  • 36
  • 46
6
votes
2 answers

How can I filter a Perl DBIx recordset with 2 conditions on the same column?

I'm getting my feet wet in DBIx::Class — loving it so far. One problem I am running into is that I want to query records, filtering out records that aren't in a certain date range. It took me a while to find out how to do a <= type of match instead…
BrianH
  • 7,932
  • 10
  • 50
  • 71
6
votes
1 answer

How to generate SQL schema from Perl DBIx::Class files?

Please show me how to generate SQL schema from my Perl DBIx::Class files ? Basically the reverse of make_schema_at in DBIx::Class::Schema::Loader. I have already built the Perl schema files, I just wish to recreate the schema in my SQL database. I…
null
  • 889
  • 1
  • 13
  • 24
6
votes
2 answers

Moose Triggers Not Firing When Using DBIX::Class

I am new to Moose and am trying to use it with DBIx::Class. Basic DBIC querying and updating work find, but any trigger I attempt to write does not get executed when I modify an attribute. use Modern::Perl; use Data::Dumper; my $schema =…
user287388
6
votes
3 answers

How do I cleanly extract MySQL enum values in Perl?

I have some code which needs to ensure some data is in a mysql enum prior to insertion in the database. The cleanest way I've found of doing this is the following code: sub enum_values { my ( $self, $schema, $table, $column ) = @_; # don't…
Ovid
  • 11,580
  • 9
  • 46
  • 76
6
votes
3 answers

Is there an easy way to map DBIx::Class results to my custom Moose classes?

It seems kind of a pain to have my Moose classes. Then to use DBIx::Class to get a result set..then to manually map my result set to the moose classes.
mike park
  • 61
  • 2
6
votes
2 answers

How do I add relationships at runtime using DBIx::Class and Catalyst?

In the application I am building, users can specify relationships between tables. Since I only determine this at runtime, I can't specify has_many or belongs_to relationships in the schema modules for startup. So given two tables; system and place,…
Joe
  • 61
  • 2
1
2
3
25 26