| 1 | package Rapi::Demo::Chinook::Model::DB; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Moo; | ||
| 7 | extends 'Catalyst::Model::DBIC::Schema'; | ||
| 8 | |||
| 9 | __PACKAGE__->config( | ||
| 10 | schema_class => 'Rapi::Demo::Chinook::DB', | ||
| 11 | |||
| 12 | connect_info => { | ||
| 13 | dsn => 'dbi:SQLite:chinook.db', #<-- Note: this gets changed in Rapi::Demo::Chinook | ||
| 14 | user => '', | ||
| 15 | password => '', | ||
| 16 | sqlite_unicode => q{1}, | ||
| 17 | on_connect_call => q{use_foreign_keys}, | ||
| 18 | quote_names => q{1}, | ||
| 19 | }, | ||
| 20 | |||
| 21 | # Configs copied from the RA::ChinookDemo (http://www.rapidapp.info/demos/chinook) | ||
| 22 | RapidDbic => { | ||
| 23 | hide_fk_columns => 1, | ||
| 24 | grid_params => { | ||
| 25 | '*defaults' => { # Defaults for all Sources | ||
| 26 | updatable_colspec => ['*'], | ||
| 27 | creatable_colspec => ['*'], | ||
| 28 | destroyable_relspec => ['*'] | ||
| 29 | }, # ('*defaults') | ||
| 30 | Album => { | ||
| 31 | include_colspec => ['*','artistid.name'] | ||
| 32 | }, | ||
| 33 | Genre => { | ||
| 34 | # Leave persist_immediately on without the add form | ||
| 35 | # (inserts blank/default rows immediately): | ||
| 36 | use_add_form => 0, | ||
| 37 | # No delete confirmations: | ||
| 38 | confirm_on_destroy => 0 | ||
| 39 | }, | ||
| 40 | Invoice => { | ||
| 41 | # Delete invoice_lines with invoice (cascade): | ||
| 42 | destroyable_relspec => ['*','invoice_lines'] | ||
| 43 | }, | ||
| 44 | InvoiceLine => { | ||
| 45 | # join all columns of all relationships (first-level): | ||
| 46 | include_colspec => ['*','*.*'], | ||
| 47 | updatable_colspec => [ | ||
| 48 | 'invoiceid','unitprice', | ||
| 49 | 'invoiceid.billing*' | ||
| 50 | ], | ||
| 51 | }, | ||
| 52 | MediaType => { | ||
| 53 | # Use the grid itself to set new row values: | ||
| 54 | use_add_form => 0, #<-- also disables autoload_added_record | ||
| 55 | persist_immediately => { | ||
| 56 | create => 0, | ||
| 57 | update => 1, | ||
| 58 | destroy => 1 | ||
| 59 | }, | ||
| 60 | # No delete confirmations: | ||
| 61 | confirm_on_destroy => 0 | ||
| 62 | }, | ||
| 63 | Track => { | ||
| 64 | include_colspec => ['*','albumid.artistid.*'], | ||
| 65 | # Don't persist anything immediately: | ||
| 66 | persist_immediately => { | ||
| 67 | # 'create => 0' changes these defaults: | ||
| 68 | # use_add_form => '0' (normally 'tab') | ||
| 69 | # autoload_added_record => 0 (normally '1') | ||
| 70 | create => 0, | ||
| 71 | update => 0, | ||
| 72 | destroy => 0 | ||
| 73 | }, | ||
| 74 | # Use the add form in a window: | ||
| 75 | use_add_form => 'window' | ||
| 76 | }, | ||
| 77 | }, # (grid_params) | ||
| 78 | TableSpecs => { | ||
| 79 | Album => { | ||
| 80 | display_column => 'title' | ||
| 81 | }, | ||
| 82 | Artist => { | ||
| 83 | display_column => 'name' | ||
| 84 | }, | ||
| 85 | Employee => { | ||
| 86 | # Use virtual column 'full_name' as the display column: | ||
| 87 | display_column => 'full_name' | ||
| 88 | }, | ||
| 89 | Genre => { | ||
| 90 | display_column => 'name', | ||
| 91 | auto_editor_type => 'combo' | ||
| 92 | }, | ||
| 93 | MediaType => { | ||
| 94 | display_column => 'name', | ||
| 95 | auto_editor_type => 'combo' | ||
| 96 | }, | ||
| 97 | Track => { | ||
| 98 | columns => { | ||
| 99 | bytes => { | ||
| 100 | renderer => 'Ext.util.Format.fileSize' | ||
| 101 | }, | ||
| 102 | unitprice => { | ||
| 103 | renderer => 'Ext.util.Format.usMoney', | ||
| 104 | header => 'Price', | ||
| 105 | width => 50 | ||
| 106 | }, | ||
| 107 | name => { | ||
| 108 | header => 'Name', width => 140 | ||
| 109 | }, | ||
| 110 | albumid => { | ||
| 111 | header => 'Album', width => 130 | ||
| 112 | }, | ||
| 113 | mediatypeid => { | ||
| 114 | header => 'Media Type', width => 165 | ||
| 115 | }, | ||
| 116 | genreid => { | ||
| 117 | header => 'Genre', width => 110 | ||
| 118 | }, | ||
| 119 | playlist_tracks => { | ||
| 120 | sortable => 0 | ||
| 121 | }, | ||
| 122 | milliseconds => { | ||
| 123 | hidden => 1 | ||
| 124 | }, | ||
| 125 | composer => { | ||
| 126 | hidden => 1, | ||
| 127 | no_quick_search => 1, | ||
| 128 | no_multifilter => 1 | ||
| 129 | }, | ||
| 130 | trackid => { | ||
| 131 | #allow_add => 1, | ||
| 132 | #allow_edit => 1 | ||
| 133 | no_column => 1, | ||
| 134 | no_quick_search => 1, | ||
| 135 | no_multifilter => 1 | ||
| 136 | }, | ||
| 137 | }, | ||
| 138 | }, | ||
| 139 | }, # (TableSpecs) | ||
| 140 | virtual_columns => { | ||
| 141 | Employee => { | ||
| 142 | full_name => { | ||
| 143 | data_type => "varchar", | ||
| 144 | is_nullable => 0, | ||
| 145 | size => 255, | ||
| 146 | sql => 'SELECT self.firstname || " " || self.lastname', | ||
| 147 | set_function => sub { | ||
| 148 | my ($row, $value) = @_; | ||
| 149 | my ($fn, $ln) = split(/\s+/,$value,2); | ||
| 150 | $row->update({ firstname=>$fn, lastname=>$ln }); | ||
| 151 | }, | ||
| 152 | }, | ||
| 153 | }, | ||
| 154 | }, # (virtual_columns) | ||
| 155 | } # (RapidDbic) | ||
| 156 | ); | ||
| 157 | |||
| 158 | |||
| 159 | 1; |