From 4e86e08c05fa9e803824e6af93ddf00272281977 Mon Sep 17 00:00:00 2001 From: Will Budic Date: Mon, 20 May 2024 20:07:24 +1000 Subject: [PATCH] cleanup --- Specifications_For_CNF_Data_Tables.md | 163 ++++++++++++++++++++++++++ system/modules/CNFMeta.pm | 5 +- system/modules/MarkdownPlugin.pm | 9 +- tests/DatabaseCentralPlugin.pm | 2 + tests/testExperimental.pl | 30 +++++ 5 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 Specifications_For_CNF_Data_Tables.md diff --git a/Specifications_For_CNF_Data_Tables.md b/Specifications_For_CNF_Data_Tables.md new file mode 100644 index 0000000..128d5ab --- /dev/null +++ b/Specifications_For_CNF_Data_Tables.md @@ -0,0 +1,163 @@ +# Configuration Network File Format Specifications - DATA + + +This section is part of the main ⇾ [CNF specifications](docs/PerlCNF/Specifications_For_CNF_ReadMe.md) + + +## 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. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
InstructionDecription
DATACNF scripted delimited data property, expected to have uniform table data rows, where very first is the table header if provided.
FILECNF scripted delimited data property is in a separate data file location, from the current script.
TABLE SQL create Table body statement part. These can unfortunately differ from one database system to another.
INDEXSQL create Index body. Indexes provide faster and more efficient data searches and updates.
VIEWSQL create View body. Views provide a faster and narrower snapshot of what can be a lot of data.
SQLDirect SQL statement without any variable unknowns.
MIGRATESame as SQL instruction, but migrations related towards tables and the application version.
+ +## CNFMeta SQL Related +> +>Meta tags in use are DATA instruction related. + +1. Meta for what actions on data and table is required. + 1. _SQL_PostgreSQL_ + - 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. _SQL_TABLE_ + - Create or link to an SQL Table equivalent. + 3. AUTO_NUMBERED + - ID column is auto numbered from 1-* if an '#' is found as the value. + 4. _HAS_HEADER_ + - 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. `ID _INT_`Name _TEXT_`Entered _DATE_`Active _BOOL_~ + +### 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 YYY-MM-DD hh:mm:ss. + 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 ⇾ [specifications](docs/PerlCNF/Specifications_For_CNF_ReadMe.md). + +### 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 + <> + ``` + +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 + < + ``` + +## CNF Meta Instructions + +> Various Meta instructions are available to aid processing and decision making + +*** + + Document is from project ⇾ + + An open source application. + + Please refer to this specifications header and item or section points, on any desired clarifications or research/troubleshooting inquires. + +
Sun Stage - v.1.0 2024
diff --git a/system/modules/CNFMeta.pm b/system/modules/CNFMeta.pm index fc73cdc..3e51030 100644 --- a/system/modules/CNFMeta.pm +++ b/system/modules/CNFMeta.pm @@ -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"; diff --git a/system/modules/MarkdownPlugin.pm b/system/modules/MarkdownPlugin.pm index 1636665..39484d9 100644 --- a/system/modules/MarkdownPlugin.pm +++ b/system/modules/MarkdownPlugin.pm @@ -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 @@ -722,10 +723,16 @@ sub style ($script){ #Images $ret =~ s/!\[(.*)\]\((.*)\)/\
\"$1\"\/<\/div>/; #Links [Duck Duck Go](https://duckduckgo.com) - $ret =~ s/\[(.*)\]\((.*)\)/\$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($desc) +} + ### # Style sheet used for HTML conversion. NOTICE - Style sheets overide sequentionaly in order of apperance. # Link with: <**> in a TREE instructed property. diff --git a/tests/DatabaseCentralPlugin.pm b/tests/DatabaseCentralPlugin.pm index 661e071..af58e4f 100644 --- a/tests/DatabaseCentralPlugin.pm +++ b/tests/DatabaseCentralPlugin.pm @@ -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. diff --git a/tests/testExperimental.pl b/tests/testExperimental.pl index 5682e51..ed26467 100644 --- a/tests/testExperimental.pl +++ b/tests/testExperimental.pl @@ -23,6 +23,36 @@ try{ flour = 75% water = 25% >> +< __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~ +>> +< __SQL_TABLE__ +ID _INT_`Name _TEXT_~ +>> +< __SQL_TABLE__ +ID _INT_`Name`Surname`MiddleName`Address`Country`State~ +#`Australia +>> +< __SQL_TABLE__ +ID _INT_`Name _TEXT_~ +#`NSW~ +#`QLD~ +#`VIC~ +#`SA~ +#`TAS~ +#`WA~ +#`NT~ +>> + +< __SQL_TABLE__ +>> + + )); my $weight = $cnf -> anon('FlourWeight'); $weight =~ s/kg/000/g; -- 2.34.1