diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..36b7cd9 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..63c47bc --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +### `dom-persist` + +This is a simple way of storing a DOM, either HTML or XML, into the Sqlite database using the D programming language. +It provides a way to cache all DOM edits in RAM and only persist to the database when flush is called. This provides +excellent performance and flexibility. DB storage is also at the element granularity providing indexing by ID. + +### `Usage` + +``` +import dom_persist; +import nodecode; + +string sqlite_filename = "dom_persist_test.db"; +if(!db_exists( sqlite_filename ) { + //create database + Database db = db_create( sqlite_filename, 1 ); + //create schema + Tree_Db.db_create_schema( db ); +} + +// create a DOM tree +Tree_Db tree = Tree_Db.createTree( db, "mytree" ); + +// get the tree (root) node +TreeNode tree_node = tree.getTreeRoot(); + +//create some nodes + +tree_node.appendChild( TreeNodeType.docType, "html" ); +auto tn_html = tree_node.appendChild( TreeNodeType.element, "html" ); + +auto tn_head = tn_html.appendChild( TreeNodeType.element, "head" ); +tn_head.appendChild( TreeNodeType.comment, "This is my comment" ); + +auto tn_body = tn_html.appendChild( TreeNodeType.element, "body" ); + +tn_body.appendChild( TreeNodeType.text, "This is some text" ); +tn_body.appendChild( TreeNodeType.text, " with more text" ); +tn_body.appendChild( TreeNodeType.element, "input" ); + +// write changes to DB +tree.flush(); + +// get the html as a text string +string html_out = tree.getTreeAsText( ); +writeln( html_out ); + + +``` diff --git a/source/dom_persist.d b/source/dom_persist.d index bcb8b2c..7cdde89 100644 --- a/source/dom_persist.d +++ b/source/dom_persist.d @@ -1,3 +1,9 @@ +/** + COPYRIGHT © 2024 JOHN PEARCEY + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.txt or copy at + https://www.boost.org/LICENSE_1_0.txt) +*/ module dom_persist; //import std.algorithm; //https://dlang.org/phobos/std_algorithm_mutation.html diff --git a/source/dom_persist_tests.d b/source/dom_persist_tests.d index ffaf9fb..04d84a3 100644 --- a/source/dom_persist_tests.d +++ b/source/dom_persist_tests.d @@ -1,3 +1,9 @@ +/** + COPYRIGHT © 2024 JOHN PEARCEY + Distributed under the Boost Software License, Version 1.0. + See accompanying file LICENSE.txt or copy at + https://www.boost.org/LICENSE_1_0.txt +*/ module dom_persist_tests; import std.stdio; diff --git a/source/nodecode.d b/source/nodecode.d index 422b2f1..79c54e7 100644 --- a/source/nodecode.d +++ b/source/nodecode.d @@ -1,3 +1,9 @@ +/** + COPYRIGHT © 2024 JOHN PEARCEY + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE.txt or copy at + https://www.boost.org/LICENSE_1_0.txt) +*/ module nodecode; import std.traits;