| 1 | package DBIO::SQLite::Introspect; | ||||||||||||
| 2 | # ABSTRACT: Introspect a SQLite database via sqlite_master and PRAGMAs | ||||||||||||
| 3 | |||||||||||||
| 4 | 197 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 197 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 197 | ▶ | use base 'DBIO::Introspect::Base'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 197 | ▶ | use DBIO::SQLite::Introspect::Tables; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 197 | ▶ | use DBIO::SQLite::Introspect::Columns; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 197 | ▶ | use DBIO::SQLite::Introspect::Indexes; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 197 | ▶ | use DBIO::SQLite::Introspect::ForeignKeys; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 197 | ▶ | use DBIO::SQLite::Util qw(column_is_nullable); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | |||||||||||||
| 16 | 26 | ▶ | sub _build_model { | ||||||||||
|
Subroutine
_build_model: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 26 | my ($self) = @_; | |||||||||||
| 18 | |||||||||||||
| 19 | 26 | my $tables = DBIO::SQLite::Introspect::Tables->fetch($self->dbh); | |||||||||||
| 20 | 26 | my $columns = DBIO::SQLite::Introspect::Columns->fetch($self->dbh, $tables); | |||||||||||
| 21 | 26 | my $indexes = DBIO::SQLite::Introspect::Indexes->fetch($self->dbh, $tables); | |||||||||||
| 22 | 26 | my $fks = DBIO::SQLite::Introspect::ForeignKeys->fetch($self->dbh, $tables); | |||||||||||
| 23 | |||||||||||||
| 24 | return { | ||||||||||||
| 25 | 26 | tables => $tables, | |||||||||||
| 26 | columns => $columns, | ||||||||||||
| 27 | indexes => $indexes, | ||||||||||||
| 28 | foreign_keys => $fks, | ||||||||||||
| 29 | }; | ||||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | # SQLite-specific override: PRAGMA table_info reports PRIMARY KEY columns | ||||||||||||
| 33 | # as notnull=0 (the PK constraint is separate from the NOT NULL attribute), | ||||||||||||
| 34 | # but a PK column is logically NOT NULL. The canonical Base contract derives | ||||||||||||
| 35 | # is_nullable from not_null alone, so without this override PK columns would | ||||||||||||
| 36 | # wrongly report is_nullable=1. column_is_nullable is the single source of | ||||||||||||
| 37 | # truth for that rule (shared with DBIO::SQLite::Storage). | ||||||||||||
| 38 | 1 | ▶ | sub table_columns_info { | ||||||||||
|
Subroutine
table_columns_info: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 39 | 1 | my ($self, $key) = @_; | |||||||||||
| 40 | 1 | my $info = $self->SUPER::table_columns_info($key); | |||||||||||
| 41 | 1 | ▶ | for my $col (@{ $self->model->{columns}{$key} || [] }) { | ||||||||||
|
Condition50%1/2
$self->model->{'columns'}{$key} || []
MC/DC0%0/1
$self->model->{'columns'}{$key} || []
$self->model->{'columns'}{$key}
Truth table50%1/2
A
A= $self->model->{'columns'}{$key}
| |||||||||||||
| 42 | $info->{ $col->{column_name} }{is_nullable} = | ||||||||||||
| 43 | 3 | column_is_nullable($col->{not_null}, $col->{is_pk}); | |||||||||||
| 44 | } | ||||||||||||
| 45 | 1 | return $info; | |||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | 197 | 1; | |||||||||||
| 49 | |||||||||||||
| 50 | __END__ | ||||||||||||
| 51 | |||||||||||||
| 52 | =pod | ||||||||||||
| 53 | |||||||||||||
| 54 | =encoding UTF-8 | ||||||||||||
| 55 | |||||||||||||
| 56 | =head1 NAME | ||||||||||||
| 57 | |||||||||||||
| 58 | DBIO::SQLite::Introspect - Introspect a SQLite database via sqlite_master and PRAGMAs | ||||||||||||
| 59 | |||||||||||||
| 60 | =head1 VERSION | ||||||||||||
| 61 | |||||||||||||
| 62 | version 0.900001 | ||||||||||||
| 63 | |||||||||||||
| 64 | =head1 DESCRIPTION | ||||||||||||
| 65 | |||||||||||||
| 66 | C<DBIO::SQLite::Introspect> reads the live state of a SQLite database | ||||||||||||
| 67 | via C<sqlite_master> and the relevant C<PRAGMA> statements and returns a | ||||||||||||
| 68 | unified model hashref. It is the source side of the test-deploy-and- | ||||||||||||
| 69 | compare strategy used by L<DBIO::SQLite::Deploy>. | ||||||||||||
| 70 | |||||||||||||
| 71 | my $intro = DBIO::SQLite::Introspect->new(dbh => $dbh); | ||||||||||||
| 72 | my $model = $intro->model; | ||||||||||||
| 73 | # $model->{tables}, $model->{columns}, $model->{indexes}, $model->{foreign_keys} | ||||||||||||
| 74 | |||||||||||||
| 75 | The model shape mirrors L<DBIO::PostgreSQL::Introspect> so the same | ||||||||||||
| 76 | diff/deploy patterns apply, but only covers what SQLite actually has | ||||||||||||
| 77 | (no schemas, types, functions, RLS). | ||||||||||||
| 78 | |||||||||||||
| 79 | =head1 AUTHOR | ||||||||||||
| 80 | |||||||||||||
| 81 | DBIO & DBIx::Class Authors | ||||||||||||
| 82 | |||||||||||||
| 83 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 84 | |||||||||||||
| 85 | Copyright (C) 2026 DBIO Authors | ||||||||||||
| 86 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||
| 87 | Based on DBIx::Class, heavily modified. | ||||||||||||
| 88 | |||||||||||||
| 89 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 90 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 91 | |||||||||||||
| 92 | =cut | ||||||||||||