This shows you the differences between two versions of the page.
esmith:db:db [2015/05/22 07:34] stephdl [EXAMPLE] |
esmith:db:db [2019/06/05 19:48] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== esmith:: | ||
- | | ||
- | |||
- | In a root terminal you can do the command below if you want to display the up-to-date content | ||
- | | ||
- | |||
- | ===== SYNOPSIS ===== | ||
- | Works just like an esmith::DB class except where noted | ||
- | |||
- | ===== DESCRIPTION ===== | ||
- | This module provides an abstracted interface to esmith::db flat-file databases. | ||
- | |||
- | You should use this instead of esmith::db, and replace any existing esmith::db code with this. | ||
- | |||
- | Note for esmith::db users the old concept of a ’type’ is now simply another property. | ||
- | |||
- | my $type = $record-> | ||
- | |||
- | replaces db_get_type(). | ||
- | |||
- | The $record returned by esmith:: | ||
- | |||
- | ==== Methods ==== | ||
- | |||
- | |||
- | === create === | ||
- | Puts its error on esmith:: | ||
- | |||
- | open | ||
- | | ||
- | | ||
- | | ||
- | file | ||
- | | ||
- | get | ||
- | | ||
- | | ||
- | |||
- | ===== EXAMPLE ===== | ||
- | The full docs can be found in esmith::DB and esmith:: | ||
- | |||
- | ==== opening the default config ==== | ||
- | use esmith:: | ||
- | my %config; | ||
- | tie %config, ’esmith:: | ||
- | |||
- | Now: | ||
- | |||
- | use esmith:: | ||
- | my $config = esmith:: | ||
- | |||
- | ==== opening a specific config database ==== | ||
- | my %config; | ||
- | tie %config, ’esmith:: | ||
- | |||
- | Now: | ||
- | |||
- | my $config = esmith:: | ||
- | |||
- | ==== creating a new config database ==== | ||
- | This one’s important. | ||
- | |||
- | my %config; | ||
- | tie %config, ’esmith:: | ||
- | |||
- | Now: | ||
- | |||
- | my $config = esmith:: | ||
- | |||
- | ==== checking if a record exists ==== | ||
- | print " | ||
- | |||
- | now: | ||
- | |||
- | print " | ||
- | |||
- | ==== creating a new record ==== | ||
- | Previously you could just create records on the fly: | ||
- | |||
- | # single value | ||
- | | ||
- | |||
- | # with properties | ||
- | | ||
- | |||
- | Now you have to explicitly create them: | ||
- | |||
- | # single value | ||
- | my $foo = $config-> | ||
- | | ||
- | |||
- | # with properties | ||
- | my %defaults = ( ’type’ | ||
- | ’linux’ | ||
- | ’windows’ => ’stable? | ||
- | my $foo = $config-> | ||
- | |||
- | Note that ’type’ is now just another property. | ||
- | |||
- | Here’s a handy " | ||
- | |||
- | my $rec = $config-> | ||
- | | ||
- | |||
- | ==== getting a value ==== | ||
- | Entries in a database should no longer be thought of as values, but as records. | ||
- | |||
- | my $val = $config{foo}; | ||
- | |||
- | Now this only works with entries with single value. Things with multiple properties are dealt with differently. | ||
- | |||
- | my $record = $config-> | ||
- | my $val = $record-> | ||
- | |||
- | ==== setting a value ==== | ||
- | | ||
- | |||
- | now | ||
- | |||
- | my $record = $config-> | ||
- | | ||
- | |||
- | ==== getting a property ==== | ||
- | my $this = db_get_prop(\%config, | ||
- | |||
- | now: | ||
- | |||
- | my $foo = $config-> | ||
- | my $this = $foo-> | ||
- | |||
- | ==== getting & setting properties ==== | ||
- | my $val = db_get_prop(\%config, | ||
- | | ||
- | |||
- | now: | ||
- | |||
- | my $val = $record-> | ||
- | | ||
- | |||
- | ==== get/setting the type ==== | ||
- | my $type = db_get_type(\%config, | ||
- | | ||
- | |||
- | type is now just a property | ||
- | |||
- | my $record = $db-> | ||
- | my $type = $record-> | ||
- | | ||
- | |||
- | ==== getting all the properties ==== | ||
- | my %props = db_get_prop(\%config, | ||
- | |||
- | now | ||
- | |||
- | my %props = $record-> | ||
- | |||
- | === AUTHOR === | ||
- | SME Server Developers < | ||
- | {{tag> neth-development sme-development }} | ||