{"id":83,"date":"2016-10-14T17:26:01","date_gmt":"2016-10-14T17:26:01","guid":{"rendered":"https:\/\/blog.diggernaut.com\/?p=83"},"modified":"2019-01-12T20:43:51","modified_gmt":"2019-01-12T20:43:51","slug":"i-want-to-have-my-data-flow-directly-from-digger-to-rdbms","status":"publish","type":"post","link":"https:\/\/www.diggernaut.com\/blog\/i-want-to-have-my-data-flow-directly-from-digger-to-rdbms\/","title":{"rendered":"I want to have my data flow directly from digger to RDBMS"},"content":{"rendered":"<h3>Do you want to save data to RDBMS?<\/h3>\n<p>It\u2019s not that hard.<\/p>\n<p>So today I\u2019m going to show you how easy it can be done using <a href=\"https:\/\/www.diggernaut.com\">Diggernaut\u2019s<\/a> Compile Service.<\/p>\n<h4>Stage One: preparation.<\/h4>\n<p>This is test configuration you can use as a sample for education, its fully working example and doesn\u2019t break any TOS. So its safe to use it in any country.<\/p>\n<pre class=\"language-yaml line-numbers\"><code class=\"language-yaml\">---\ndo:\n  - walk:\n      to: &#039;https:\/\/www.diggernaut.com\/sandbox\/&#039;\n      do:\n        - find:\n            path: &#039;div:nth-child(6) .result-content&#039;\n            do:\n              - find:\n                  path: h3\n                  do:\n                    - parse\n                    - variable_clear: name\n                    - variable_set: name\n              - find:\n                  path: p\n                  do:\n                    - parse\n                    - variable_clear: description\n                    - variable_set: description\n              - find:\n                  path: &#039;tbody > tr&#039;\n                  do:\n                    - parse\n                    - object_new: item\n                    - variable_get: name\n                    - object_field_set:\n                        object: item\n                        field: name\n                    - variable_get: description\n                    - object_field_set:\n                        object: item\n                        field: descr\n                    - object_new: date\n                    - find:\n                        path: &#039;.col5 > .nowrap:nth-child(1)&#039;\n                        do:\n                          - parse\n                          - object_field_set:\n                              object: date\n                              field: date\n                    - find:\n                        path: &#039;.col5 > .nowrap:nth-child(2)&#039;\n                        do:\n                          - parse\n                          - object_field_set:\n                              object: date\n                              field: date\n                              joinby: &quot; - &quot;\n                    - find:\n                        path: .col6\n                        do:\n                          - parse\n                          - normalize:\n                              routine: replace_substring\n                              args:\n                                  \\s*(\\d+)A: &#039;s&#039;   \n                          - object_field_set:\n                              object: date\n                              field: time\n                    - object_save:\n                        name: date\n                        to: item\n                    - object_save:\n                        name: item<\/code><\/pre>\n<p>Resulting dataset has the following structure:<\/p>\n<pre><code class=\"language-js\">item: [\n        {\n            &quot;name&quot;:&quot;&quot;,\n            &quot;descr&quot;:&quot;&quot;,\n            &quot;date&quot;: [\n                        {\n                            &quot;date&quot;:&quot;,\n                            &quot;time&quot;:&quot;&quot;\n                        }\n                        ...\n                        ...\n                    ]\n            },\n            ...\n            ...\n        ]\n<\/code><\/pre>\n<p>Let\u2019s prepare our database. Digger can save data to MySQL, Microsoft SQL and PostgreSQL. So we need to create database and tables for our data.<\/p>\n<h4>MYSQL<\/h4>\n<pre><code class=\"language-sql\">    CREATE DATABASE `digger`;\n\n    CREATE TABLE `items` (\n        `id` INT(11) NOT NULL AUTO_INCREMENT,\n        `name` VARCHAR(50) NULL DEFAULT NULL,\n        `descr` TEXT NULL,\n        PRIMARY KEY (`id`)\n    )\n    COLLATE=&#039;utf8_general_ci&#039;\n    ENGINE=InnoDB;\n\n    CREATE TABLE `dates` (\n        `id` INT(11) NOT NULL AUTO_INCREMENT,\n        `item_id` INT(11) NOT NULL,\n        `date` VARCHAR(50) NULL DEFAULT NULL,\n        `time` VARCHAR(50) NULL DEFAULT NULL,\n        INDEX `Index 1` (`id`),\n        INDEX `FK__items` (`item_id`),\n        CONSTRAINT `FK__items` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION\n        )\n    COLLATE=&#039;utf8_general_ci&#039;\n    ENGINE=InnoDB;\n<\/code><\/pre>\n<h4>MS SQL<\/h4>\n<pre><code class=\"language-sql\">    CREATE DATABASE `digger`;\n\n    CREATE TABLE `items` (\n        id INT NOT NULL IDENTITY(1,1) CONSTRAINT pk_items_pid PRIMARY KEY,\n        `name` VARCHAR(50),\n        `descr` TEXT \n    );\n\n    CREATE TABLE `dates` (\n        id INT NOT NULL IDENTITY(1,1) CONSTRAINT pk_dates_pid PRIMARY KEY,\n        item_id int CONSTRAINT fk_item_id FOREIGN KEY(item_id) REFERENCES items(id),\n        date TEXT,\n        time TEXT \n    );\n<\/code><\/pre>\n<h4>PostgreSQL<\/h4>\n<pre><code class=\"language-sql\">    CREATE DATABASE digger;\n\n    CREATE TABLE items (\n        id SERIAL PRIMARY KEY,\n        name varchar(50),\n        descr text,\n    );\n\n    CREATE TABLE dates (\n        id SERIAL PRIMARY KEY,\n        date varchar(50),\n        time varchar(50),\n        item_id integer REFERENCES items (id),\n    );\n<\/code><\/pre>\n<p>Now let\u2019s compile our digger.<\/p>\n<figure id=\"attachment_mmd_349\" class=\"wp-block-image alignnone\"><a href=\"https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compile.jpg\"><img width=\"1052\" height=\"305\" src=\"https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compile.jpg\" class=\"attachment-full size-full\" alt=\"\" decoding=\"async\" loading=\"lazy\" align=\"none\" srcset=\"https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compile.jpg 1052w, https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compile-768x223.jpg 768w\" sizes=\"auto, (max-width: 1052px) 100vw, 1052px\" \/><\/a><\/figure>\n<figure id=\"attachment_mmd_351\" class=\"wp-block-image alignnone\"><a href=\"https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilemysql.jpg\"><img width=\"818\" height=\"617\" src=\"https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilemysql.jpg\" class=\"attachment-full size-full\" alt=\"\" decoding=\"async\" loading=\"lazy\" align=\"none\" srcset=\"https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilemysql.jpg 818w, https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilemysql-290x220.jpg 290w, https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilemysql-768x579.jpg 768w\" sizes=\"auto, (max-width: 818px) 100vw, 818px\" \/><\/a><\/figure>\n<figure id=\"attachment_mmd_352\" class=\"wp-block-image alignnone\"><a href=\"https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilemssql.jpg\"><img width=\"815\" height=\"616\" src=\"https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilemssql.jpg\" class=\"attachment-full size-full\" alt=\"\" decoding=\"async\" loading=\"lazy\" align=\"none\" srcset=\"https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilemssql.jpg 815w, https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilemssql-290x220.jpg 290w, https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilemssql-768x580.jpg 768w\" sizes=\"auto, (max-width: 815px) 100vw, 815px\" \/><\/a><\/figure>\n<figure id=\"attachment_mmd_353\" class=\"wp-block-image alignnone\"><a href=\"https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilePostgre.jpg\"><img width=\"819\" height=\"614\" src=\"https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilePostgre.jpg\" class=\"attachment-full size-full\" alt=\"\" decoding=\"async\" loading=\"lazy\" align=\"none\" srcset=\"https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilePostgre.jpg 819w, https:\/\/www.diggernaut.com\/blog\/wp-content\/uploads\/2016\/10\/compilePostgre-768x576.jpg 768w\" sizes=\"auto, (max-width: 819px) 100vw, 819px\" \/><\/a><\/figure>\n<p>Download it and run. Once the job is finished, you can see data in your DB. So now you can have your data flow directly from digger to your database without a hassle.<\/p>","protected":false},"excerpt":{"rendered":"<p>Do you want to save data to RDBMS? It\u2019s not that hard. So today I\u2019m going to show you how easy it can be done using Diggernaut\u2019s Compile Service. Stage One: preparation. This is test configuration you can use as a sample for education, its fully working example and doesn\u2019t break any TOS. So its [&hellip;]<\/p>","protected":false},"author":5,"featured_media":85,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,2],"tags":[],"class_list":["post-83","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learning-meta-language","category-web-scraping"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.diggernaut.com\/blog\/wp-json\/wp\/v2\/posts\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.diggernaut.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.diggernaut.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.diggernaut.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.diggernaut.com\/blog\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":5,"href":"https:\/\/www.diggernaut.com\/blog\/wp-json\/wp\/v2\/posts\/83\/revisions"}],"predecessor-version":[{"id":681,"href":"https:\/\/www.diggernaut.com\/blog\/wp-json\/wp\/v2\/posts\/83\/revisions\/681"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.diggernaut.com\/blog\/wp-json\/wp\/v2\/media\/85"}],"wp:attachment":[{"href":"https:\/\/www.diggernaut.com\/blog\/wp-json\/wp\/v2\/media?parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.diggernaut.com\/blog\/wp-json\/wp\/v2\/categories?post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.diggernaut.com\/blog\/wp-json\/wp\/v2\/tags?post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}