1DBIx::Class::ResultSourUcsee:r:VCioenwt(r3i)buted Perl DDoBcIuxm:e:nCtlaatsiso:n:ResultSource::View(3)
2
3
4

NAME

6       DBIx::Class::ResultSource::View - ResultSource object representing a
7       view
8

SYNOPSIS

10         package MyApp::Schema::Result::Year2000CDs;
11
12         use base qw/DBIx::Class::Core/;
13
14         __PACKAGE__->table_class('DBIx::Class::ResultSource::View');
15
16         __PACKAGE__->table('year2000cds');
17         __PACKAGE__->result_source_instance->is_virtual(1);
18         __PACKAGE__->result_source_instance->view_definition(
19             "SELECT cdid, artist, title FROM cd WHERE year ='2000'"
20         );
21         __PACKAGE__->add_columns(
22           'cdid' => {
23             data_type => 'integer',
24             is_auto_increment => 1,
25           },
26           'artist' => {
27             data_type => 'integer',
28           },
29           'title' => {
30             data_type => 'varchar',
31             size      => 100,
32           },
33         );
34

DESCRIPTION

36       View object that inherits from DBIx::Class::ResultSource
37
38       This class extends ResultSource to add basic view support.
39
40       A view has a "view_definition", which contains a SQL query. The query
41       can only have parameters if "is_virtual" is set to true. It may contain
42       JOINs, sub selects and any other SQL your database supports.
43
44       View definition SQL is deployed to your database on "deploy" in
45       DBIx::Class::Schema unless you set "is_virtual" to true.
46
47       Deploying the view does not translate it between different database
48       syntaxes, so be careful what you write in your view SQL.
49
50       Virtual views ("is_virtual" true), are assumed to not exist in your
51       database as a real view. The "view_definition" in this case replaces
52       the view name in a FROM clause in a subselect.
53

EXAMPLES

55       Having created the MyApp::Schema::Year2000CDs schema as shown in the
56       SYNOPSIS above, you can then:
57
58         $2000_cds = $schema->resultset('Year2000CDs')
59                            ->search()
60                            ->all();
61         $count    = $schema->resultset('Year2000CDs')
62                            ->search()
63                            ->count();
64
65       If you modified the schema to include a placeholder
66
67         __PACKAGE__->result_source_instance->view_definition(
68             "SELECT cdid, artist, title FROM cd WHERE year = ?"
69         );
70
71       and ensuring you have is_virtual set to true:
72
73         __PACKAGE__->result_source_instance->is_virtual(1);
74
75       You could now say:
76
77         $2001_cds = $schema->resultset('Year2000CDs')
78                            ->search({}, { bind => [2001] })
79                            ->all();
80         $count    = $schema->resultset('Year2000CDs')
81                            ->search({}, { bind => [2001] })
82                            ->count();
83

SQL EXAMPLES

85       is_virtual set to false
86             $schema->resultset('Year2000CDs')->all();
87
88             SELECT cdid, artist, title FROM year2000cds me
89
90       is_virtual set to true
91             $schema->resultset('Year2000CDs')->all();
92
93             SELECT cdid, artist, title FROM
94               (SELECT cdid, artist, title FROM cd WHERE year ='2000') me
95

METHODS

97   is_virtual
98         __PACKAGE__->result_source_instance->is_virtual(1);
99
100       Set to true for a virtual view, false or unset for a real database-
101       based view.
102
103   view_definition
104         __PACKAGE__->result_source_instance->view_definition(
105             "SELECT cdid, artist, title FROM cd WHERE year ='2000'"
106             );
107
108       An SQL query for your view. Will not be translated across database
109       syntaxes.
110
111   deploy_depends_on
112         __PACKAGE__->result_source_instance->deploy_depends_on(
113             ["MyApp::Schema::Result::Year","MyApp::Schema::Result::CD"]
114             );
115
116       Specify the views (and only the views) that this view depends on.  Pass
117       this an array reference of fully qualified result classes.
118

OVERRIDDEN METHODS

120   from
121       Returns the FROM entry for the table (i.e. the view name) or the SQL as
122       a subselect if this is a virtual view.
123

OTHER METHODS

125   new
126       The constructor.
127

FURTHER QUESTIONS?

129       Check the list of additional DBIC resources.
130
132       This module is free software copyright by the DBIx::Class (DBIC)
133       authors. You can redistribute it and/or modify it under the same terms
134       as the DBIx::Class library.
135
136
137
138perl v5.36.0                      2022-07-22DBIx::Class::ResultSource::View(3)
Impressum