File: Sqlite.pm

package info (click to toggle)
libur-perl 0.470%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,184 kB
  • sloc: perl: 61,813; javascript: 255; xml: 108; sh: 13; makefile: 9
file content (67 lines) | stat: -rw-r--r-- 1,514 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package UR::Namespace::Command::Define::Datasource::Sqlite;

use strict;
use warnings;
use UR;
our $VERSION = "0.47"; # UR $VERSION;

use IO::File;

UR::Object::Type->define(
    class_name => __PACKAGE__,
    is => [ 'UR::Namespace::Command::Define::Datasource::Rdbms' ],
);

sub help_brief {
   "Add a SQLite data source to the current namespace."
}

sub help_synopsis {
    return <<EOS
  cd Acme

  ur define datasource sqlite --dsname MyDB1 
  # writes Acme::DataSource::MyDB1 to work with Acme/DataSource/MyDB1.sqlite3
  
  ur define datasource sqlite --dsname MyDB2 --server /var/lib/acmeapp/mydb2.sqlite3
  # writes Acme::DataSource::MyDB2 to work with the specified sqlite file
EOS
}

sub _data_source_sub_class_name {
    "UR::DataSource::SQLite"
}

sub server {
    my $self = shift;

    my $super_server = $self->super_can('server');
    if (@_) {
        # unusual case, setting the server
        return $super_server($self,@_);
    }

    my $server = $super_server->($self);
    unless ($server) {
        $server = $self->data_source_module_pathname();
        $server =~ s/\.pm$/.sqlite3/;
        $super_server->($self,$server);
    }
    return $server;
}

sub _post_module_written {
    my $self = shift;

    # Create a new, empty DB if it dosen't exist yet
    my $pathname = $self->server;
    $pathname =~ s/\.pm$/.sqlite3/;
    IO::File->new($pathname, O_WRONLY | O_CREAT) unless (-f $pathname);
    $self->status_message("A   $pathname (empty database schame)");

    return 1;
}


1;