]> lifelog.hopto.org Git - PerlCNF.git/commitdiff
cleanup
authorWill Budic <redacted>
Mon, 20 May 2024 10:07:24 +0000 (20:07 +1000)
committerWill Budic <redacted>
Mon, 20 May 2024 10:07:24 +0000 (20:07 +1000)
Specifications_For_CNF_Data_Tables.md [new file with mode: 0644]
system/modules/CNFMeta.pm
system/modules/MarkdownPlugin.pm
tests/DatabaseCentralPlugin.pm
tests/testExperimental.pl

diff --git a/Specifications_For_CNF_Data_Tables.md b/Specifications_For_CNF_Data_Tables.md
new file mode 100644 (file)
index 0000000..128d5ab
--- /dev/null
@@ -0,0 +1,163 @@
+# Configuration Network File Format Specifications - DATA
+
+
+<span id="content" class="span-content">This section is part of the main ⇾ [CNF specifications](docs/PerlCNF/Specifications_For_CNF_ReadMe.md)</span>
+
+
+## CNF Data and SQL Document Section
+
+CNF scripted delimited data property, having uniform table data rows.
+The data is converted by default into arrays as rows. If it contains a header (recommended) these becomes the header of the data. A table header will be produced that contains the row's column's information, like name and type specs.
+The table header contains the actual data reference.
+
+This table is and specs are used to access, map and translate the data.
+There is a basic header being created by the parser and placed into its data hash.
+
+Example on how to access the data table of a property.
+
+```Perl
+my $table  = CNFParser->new(...)->data(){'MyDataProperty'};
+my $header = $$table->{header};
+my $lbls   = CNFMeta::_deRefArray(@$$header[0]);
+my $spec   = CNFMeta::_deRefArray(@$$header[3]);
+my $data   = CNFMeta::_deRefArray($$table->{data});
+```
+
+## SQL Based CNF Instruction
+>
+> The following reserved words or instructions a data and SQL related.
+<style>
+    .CNF_md_table{
+        background-color: beige;
+        td{
+            border-right: solid black 1px;
+            border-bottom: solid #ab0433 1px;
+        }
+    }
+</style>
+<table class="CNF_md_table">
+ <thead>
+  <tr>
+   <th>Instruction</th>
+   <th>Decription</th>
+  </tr>
+ </thead>
+ <tbody>
+  <tr>
+   <td>DATA</td>
+   <td>CNF scripted delimited data property, expected to have uniform table data rows, where very first is the table header if provided.</td>
+  </tr>
+  <tr>
+   <td>FILE</td>
+   <td>CNF scripted delimited data property is in a separate data file location, from the current script.</td>
+  </tr>
+    <tr>
+   <td>TABLE</td>
+   <td> SQL create Table body statement part. These can unfortunately differ from one database system to another.</td>
+  </tr>
+    <tr>
+   <td>INDEX</td>
+   <td>SQL create Index body. Indexes provide faster and more efficient data searches and updates.</td>
+  </tr>
+    <tr>
+   <td>VIEW</td>
+   <td>SQL create View body. Views provide a faster and narrower snapshot of what can be a lot of data.</td>
+  </tr>
+      <tr>
+   <td>SQL</td>
+   <td>Direct SQL statement without any variable unknowns.</td>
+  </tr>
+    <tr>
+   <td>MIGRATE</td>
+   <td>Same as SQL instruction, but migrations related towards tables and the application version.</td>
+  </tr>
+ </tbody>
+</table>
+
+## CNFMeta SQL Related
+>
+>Meta tags in use are DATA instruction related.
+
+1. Meta for what actions on data and table is required.
+   1. <code>_SQL_PostgreSQL_</code>
+      - Data is to be linked or related to a Postgres SQL Database, default is SQLite.
+      - In cases where the SQL underlining driver is something different from SQLite or Postgres this should be set to true and hope for the best.
+   2. <code>_SQL_TABLE_</code>
+      - Create or link to an SQL Table equivalent.
+   3. <code>AUTO_NUMBERED</code>
+      - ID column is auto numbered from 1-* if an '#' is found as the value.
+   4. <code>_HAS_HEADER_</code>
+      - Specifically instruct first record is the header labels and specs for the columns.
+   5. Column CNF type is optionally placed next to header label, default column type is TEXT.
+      - i.e. <code> `ID _INT_`Name _TEXT_`Entered _DATE_`Active _BOOL_~ </code>
+
+### Table Column CNF Data Types
+
+1. Column Data type are geared towards the CNF data type provision.
+   1. See %CNFMeta::CNF_DATA_TYPES global.
+      - BOOL INT NUMBER DATE TEXT
+   2. The date type is specific in CNF set to an universal date and time stamp of <code>YYY-MM-DD hh:mm:ss</code>.
+   3. Global $CNFMeta::SQL_CNF_VAR_LENGTH = 2024; can be changed to provide for the __TEXT__ limit translation of specified columns for a database. You can expect database errors if inserting texts that is larger than this variable limit
+
+### CNSQL Package
+
+- Accessed as a global instance of CNFParser, it is the SQL based utility for external database interactions.
+- Its actual use is expected to be via a PLUGIN instructed CNF property, to provide driver to be used, credentials and other details.
+- Example method to use it: `my $sql = CNFParser->new()->SQL();`
+- Required method when using tables with a database based storage:`$sql->initDatabase($db, $do_not_auto_synch, $map)`
+- The __DataProcessingPlugin__ provides the concept of processing the scripted data to to CNF table column type conversion.
+  - The parser provided header gets updated by this plugin.
+  - The parsers natural processing mechanism will require all SQL properties in raw form before a plugin is called to process further.
+
+>The following is extract from the original ⇾ <span id="content"> [specifications](docs/PerlCNF/Specifications_For_CNF_ReadMe.md)</span>.
+
+### CNF DATA Instruction
+
+CNF Instructions are parallel with the reserved words. Which means, you can't use these reserved words to replace with your own instruction. This section explains in more detail, what these are, and how are implemented.
+
+1. DATA
+    1. Data is specifically parsed, not requiring quoted strings and isn't delimited by new lines alone.
+    2. Data rows are ended with the __"~"__ delimiter. In the tag body.
+    3. Data columns are delimited with the invert quote __"`"__ (back tick) making the row.
+    4. First column can be taken as the unique and record identity column (UID).
+        1. If no UID is set, or specified with # or, 0, ID is considered to be auto-numbered based on data position plus 1, so not to have zero IDs.
+        2. When UID is specified, an existing previous assigned UID cannot be overridden, therefore can cause duplicates.
+        3. Data processing plugins can be installed to cater and change behavior on this whole concept.
+    5. Data is to be updated in storage if any column other than the UID, has its contents changed in the file.
+       1. This behavior can be controlled by disabling something like an auto file storage update. i.e. during application upgrades. To prevent user set settings to reset to factory defaults.
+       2. The result would then be that database already stored data remains, and only new ones are added. This exercise is out of scope of this specification.
+    6. First row labels the columns and is prefixed to PerlCNF datatype.
+       1. Generic data rows, do not require, but processors and plugins would definitely need it.
+       2. Current known types are, __@__{label} as CNFDateTime, __#__ for number or if in row autonumbering to be applied. Text is default without signifier.
+
+    ```CNF
+        <<MyAliasTable<DATA
+        01`admin`admin@inc.com`Super User~
+        02`chef`chef@inc.com`Bruno Allinoise~
+        03`juicy`sfox@inc.com`Samantha Fox~
+        >>
+    ```
+
+2. FILE
+   1. Expects a file name assigned value, file containing actual further CNF DATA rows instructions, separately.
+   2. The file is expected to be located next to the config file.
+   3. File is to be sequentially buffer read and processed instead as a whole in one go.
+   4. The same principles apply in the file as to the DATA instruction CNF tag format, that is expected to be contained in it.
+
+    ```CNF
+        <<MyItemsTbl<FILE data_my_app.cnf>
+    ```
+
+## CNF Meta Instructions
+
+> Various Meta instructions are available to aid processing and decision making
+
+***
+
+   Document is from project ⇾ <https://lifelog.hopto.org/gitweb/?p=PerlCNF.git>
+
+   An open source application.
+
+   Please refer to this specifications header and item or section points, on any desired clarifications or research/troubleshooting inquires.
+
+<center>Sun Stage - v.1.0 2024</center>
index fc73cdc93a3bec91ff743fb563695ac0c8730a98..3e51030de7ceb744be2ace77b45a42a3513ddfcf 100644 (file)
@@ -32,6 +32,9 @@ use constant PRIORITY => qr/(\s*\_+PRIORITY\_(\d+)\_+\s*)/o;
 # Global, there is possible only four CNF data types.
 our %CNF_DATA_TYPES;#         ^    #   %      @    $ (default)
 BEGIN{my $cnt =0;  foreach(qw{BOOL INT NUMBER DATE TEXT}){$CNF_DATA_TYPES{$_}=++$cnt}}
+###
+# Global setting for SQL TEXT to CNF _TEXT_ specified data type range. Programatically changable.
+our $SQL_CNF_VAR_LENGTH = 2024;
 
 sub import {
     my $caller = caller;    no strict "refs";
@@ -110,7 +113,7 @@ sub _metaTranslateDataHeader {
             }
             $spec[$i] = $CNF_DATA_TYPES{BOOL};
         }elsif($hdr =~ s/$TEXT/""/ei){
-            $body   .= "\"$hdr\" TEXT NOT NULL CHECK (length(\"$hdr\")<=2024),\n";
+            $body   .= "\"$hdr\" TEXT NOT NULL CHECK (length(\"$hdr\")<=$SQL_CNF_VAR_LENGTH),\n";
             $spec[$i] = $CNF_DATA_TYPES{TEXT};
         }elsif($hdr =~ s/$DATE/""/ei){
             $body   .= "\"$hdr\" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n";
index 1636665d9bd5ae6a9bc3300e0cee6c019bbfe5a7..39484d95a9a1e4f65540bc59231d4381bf3b1616 100644 (file)
@@ -699,6 +699,7 @@ sub propValCNF($v){
     return $v;
 }
 
+
 sub style ($script){
     MarkdownPluginException->throw(error=>"Invalid argument passed as script!",show_trace=>1) if !$script;
     #Links <https://duckduckgo.com>
@@ -722,10 +723,16 @@ sub style ($script){
     #Images
     $ret =~ s/!\[(.*)\]\((.*)\)/\<div class="div_img"><img class="md_img" src=\"$2\"\ alt=\"$1\"\/><\/div>/;
     #Links [Duck Duck Go](https://duckduckgo.com)
-    $ret =~ s/\[(.*)\]\((.*)\)/\<a href=\"$2\"\>$1\<\/a\>/;
+    $ret =~ s/\[(.*)\]\((.*)\)/&styleHREF($1,$2)/e;
     return \$ret;
 }
 
+sub styleHREF($desc,$specs){
+    my @arr = ($specs=~m/[^|]+/g);
+    my $attrs =""; $attrs .= " ".$arr[$_] foreach(1..$#arr);
+return qq(<a href="$arr[0]"$attrs>$desc</a>)
+}
+
 ###
 # Style sheet used  for HTML conversion. NOTICE - Style sheets overide sequentionaly in order of apperance.
 # Link with: <*<MarkdownPlug::CSS>*> in a TREE instructed property.
index 661e071aeb8a8f01122b200615b29377e9bd54bc..af58e4f19bba29affaf97580ab05b7adca93d9e2 100644 (file)
@@ -168,6 +168,8 @@ sub main ($self, $parser, $property) {
                 my @map  = CNFMeta::_deRefArray($tbl -> {_MAPPING_});
                 my @hdr  = CNFMeta::_deRefArray($header[0]);
                 my @spec = CNFMeta::_deRefArray($header[3]);
+
+
                 ###
                 # Following is rare to see in code, my (wbudic) forward override conditional mapping algorithm,
                 # as actual data @row length could be larger to the relative column map, of what we are inserting.
index 5682e5132b7fd9fead4fc04be4191a81809e1a3e..ed264679186543a5fce21bde72756c3a3ca842cb 100644 (file)
@@ -23,6 +23,36 @@ try{
                               flour = 75%
                               water = 25%
 >>
+<<User<TABLE> __SQL_TABLE__
+__MAP_RELATIONSHIPS_
+   Country <-1-1-> Countries@ID
+   State   <-1-1-> States@ID
+ID _INT_`Name`Surname`MN`Address`City _INT_`Country _INT_`State _INT_~
+Mike`Hamiltion`
+Unit 1, 3 Dunlop st.`Sydney`1`1`1~
+>>
+<<Cities<TABEL> __SQL_TABLE__
+ID _INT_`Name _TEXT_~
+>>
+<<Countries<TABLE> __SQL_TABLE__
+ID _INT_`Name`Surname`MiddleName`Address`Country`State~
+#`Australia
+>>
+<<States<TABEL> __SQL_TABLE__
+ID _INT_`Name _TEXT_~
+#`NSW~
+#`QLD~
+#`VIC~
+#`SA~
+#`TAS~
+#`WA~
+#`NT~
+>>
+
+<<Notes<TABLE> __SQL_TABLE__
+>>
+
+
             ));
 
    my $weight =  $cnf -> anon('FlourWeight'); $weight =~ s/kg/000/g;