| 1 | package DBIO::SQLite::Result; | ||||||||||
| 2 | # ABSTRACT: SQLite-specific Result component for DBIO | ||||||||||
| 3 | |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use base 'DBIO::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | __PACKAGE__->mk_classdata('_sqlite_indexes' => {}); | |||||||||
| 10 | |||||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | 0 | ▶ | sub sqlite_index { | ||||||||
|
Subroutine
sqlite_index: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 14 | 0 | my ($class, $name, $def) = @_; | |||||||||
| 15 | 0 | ▶ | if ($def) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 0 | my $indexes = { %{ $class->_sqlite_indexes } }; | |||||||||
| 17 | 0 | $indexes->{$name} = $def; | |||||||||
| 18 | 0 | $class->_sqlite_indexes($indexes); | |||||||||
| 19 | } | ||||||||||
| 20 | 0 | return $class->_sqlite_indexes->{$name}; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | sub sqlite_indexes { | ||||||||
|
Subroutine
sqlite_indexes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 25 | 0 | my ($class) = @_; | |||||||||
| 26 | 0 | return { %{ $class->_sqlite_indexes } }; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | 2 | 1; | |||||||||
| 31 | |||||||||||
| 32 | __END__ | ||||||||||
| 33 | |||||||||||
| 34 | =pod | ||||||||||
| 35 | |||||||||||
| 36 | =encoding UTF-8 | ||||||||||
| 37 | |||||||||||
| 38 | =head1 NAME | ||||||||||
| 39 | |||||||||||
| 40 | DBIO::SQLite::Result - SQLite-specific Result component for DBIO | ||||||||||
| 41 | |||||||||||
| 42 | =head1 VERSION | ||||||||||
| 43 | |||||||||||
| 44 | version 0.900001 | ||||||||||
| 45 | |||||||||||
| 46 | =head1 DESCRIPTION | ||||||||||
| 47 | |||||||||||
| 48 | C<DBIO::SQLite::Result> is a DBIO Result component that adds | ||||||||||
| 49 | SQLite-native metadata to a result class: custom indexes (including | ||||||||||
| 50 | partial and expression indexes). It is the counterpart to | ||||||||||
| 51 | L<DBIO::PostgreSQL::Result> / L<DBIO::MySQL::Result> and is read by | ||||||||||
| 52 | L<DBIO::SQLite::DDL> when generating install DDL. | ||||||||||
| 53 | |||||||||||
| 54 | Load it with: | ||||||||||
| 55 | |||||||||||
| 56 | package MyApp::DB::Result::User; | ||||||||||
| 57 | use base 'DBIO::Core'; | ||||||||||
| 58 | __PACKAGE__->load_components('SQLite::Result'); | ||||||||||
| 59 | |||||||||||
| 60 | __PACKAGE__->table('users'); | ||||||||||
| 61 | |||||||||||
| 62 | __PACKAGE__->sqlite_index('idx_users_active' => { | ||||||||||
| 63 | columns => ['role'], | ||||||||||
| 64 | where => "role != 'suspended'", # partial index | ||||||||||
| 65 | }); | ||||||||||
| 66 | |||||||||||
| 67 | __PACKAGE__->sqlite_index('idx_users_name_lower' => { | ||||||||||
| 68 | expression => 'lower(name)', # expression index | ||||||||||
| 69 | }); | ||||||||||
| 70 | |||||||||||
| 71 | =head1 METHODS | ||||||||||
| 72 | |||||||||||
| 73 | =head2 sqlite_index | ||||||||||
| 74 | |||||||||||
| 75 | __PACKAGE__->sqlite_index('idx_users_tags' => { | ||||||||||
| 76 | columns => ['tags'], | ||||||||||
| 77 | }); | ||||||||||
| 78 | __PACKAGE__->sqlite_index('idx_users_active' => { | ||||||||||
| 79 | columns => ['role'], | ||||||||||
| 80 | where => "role != 'suspended'", | ||||||||||
| 81 | }); | ||||||||||
| 82 | |||||||||||
| 83 | Get or set the definition for a named SQLite index. The definition | ||||||||||
| 84 | hashref accepts: | ||||||||||
| 85 | |||||||||||
| 86 | =over 4 | ||||||||||
| 87 | |||||||||||
| 88 | =item C<columns> - ArrayRef of column names | ||||||||||
| 89 | |||||||||||
| 90 | =item C<unique> - set to true for a UNIQUE index | ||||||||||
| 91 | |||||||||||
| 92 | =item C<where> - partial index predicate (SQL expression string) | ||||||||||
| 93 | |||||||||||
| 94 | =item C<expression> - expression index expression (replaces C<columns>) | ||||||||||
| 95 | |||||||||||
| 96 | =back | ||||||||||
| 97 | |||||||||||
| 98 | =head2 sqlite_indexes | ||||||||||
| 99 | |||||||||||
| 100 | my $all = $class->sqlite_indexes; # hashref of name => def | ||||||||||
| 101 | |||||||||||
| 102 | Returns a copy of all index definitions registered on this result class. | ||||||||||
| 103 | |||||||||||
| 104 | =seealso | ||||||||||
| 105 | |||||||||||
| 106 | =over 4 | ||||||||||
| 107 | |||||||||||
| 108 | =item * L<DBIO::SQLite::DDL> - consumes C<sqlite_indexes> when generating DDL | ||||||||||
| 109 | |||||||||||
| 110 | =item * L<DBIO::PostgreSQL::Result> - the PostgreSQL counterpart | ||||||||||
| 111 | |||||||||||
| 112 | =back | ||||||||||
| 113 | |||||||||||
| 114 | =head1 AUTHOR | ||||||||||
| 115 | |||||||||||
| 116 | DBIO & DBIx::Class Authors | ||||||||||
| 117 | |||||||||||
| 118 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 119 | |||||||||||
| 120 | Copyright (C) 2026 DBIO Authors | ||||||||||
| 121 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||
| 122 | Based on DBIx::Class, heavily modified. | ||||||||||
| 123 | |||||||||||
| 124 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 125 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 126 | |||||||||||
| 127 | =cut | ||||||||||