Added some stuff for the blog

This commit is contained in:
swagg boi 2023-12-02 23:03:20 -05:00
parent f93f908683
commit 6a90b0925e
5 changed files with 112 additions and 4 deletions

81
BLOG.md
View file

@ -81,3 +81,84 @@ Let's check on DB:
paste_body | text | | | paste_body | text | | |
Indexes: Indexes:
"pastes_pkey" PRIMARY KEY, btree (paste_id) "pastes_pkey" PRIMARY KEY, btree (paste_id)
Some mock-up 'model' code:
use Pastes-Bin::Model::Paste;
# No routes yet just prompt to 'fake it'
my $new-paste = prompt 'enter a new paste: ';
Pastes-Bin::Model::Paste.create: $new-paste;
Now test it:
$ ./bin/pastes-bin
enter DB password: C65VCQyp&zKsi#wKXzTLUM5V
line: -- 1 up
version: 1, direction: up
line: CREATE TABLE IF NOT EXISTS pastes (
line: paste_id SERIAL PRIMARY KEY,
line: paste_body TEXT
line: );
line: -- 1 down
version: 1, direction: down
line: DROP TABLE pastes;
current-version: allrows: [[1]]
{1 => {down => DROP TABLE pastes;
, up => CREATE TABLE IF NOT EXISTS pastes (
paste_id SERIAL PRIMARY KEY,
paste_body TEXT
);
}}
migrating from version '1' to version '1'
DB already at version 1
enter a new paste: testing 123...
Humming-Bird listening on port http://localhost:3000
^C
Now check the DB for the paste:
pastes_bin=> SELECT * FROM pastes;
paste_id | paste_body
----------+------------
(0 rows)
pastes_bin=> SELECT * FROM pastes;
paste_id | paste_body
----------+----------------
1 | testing 123...
(1 row)
End result:
use Humming-Bird::Core;
use Humming-Bird::Middleware;
use Humming-Bird::Advice;
use DB::Migration::Simple;
use DBIish;
# Local libs
use Pastes-Bin::Model::Paste;
# Logging
middleware &middleware-logger;
advice &advice-logger;
# Database stuff
my $*dbh = DBIish.connect:
'Pg',
:host<devbussy.swagg.net>,
:database<pastes_bin>,
:user<pastes_bin>,
password => prompt 'enter DB password: ';
my $m = DB::Migration::Simple.new:
:$*dbh,
:migration-file<migrations>,
:verbose;
$m.migrate: :version<1>;
# No routes yet just prompt to 'fake it'
my $new-paste = prompt 'enter a new paste: ';
Pastes-Bin::Model::Paste.create: $new-paste;

View file

@ -7,6 +7,7 @@
"DB::Migration::Simple" "DB::Migration::Simple"
], ],
"provides": { "provides": {
"Pastes-Bin": "lib/Pastes-Bin.rakumod" "Pastes-Bin": "lib/Pastes-Bin.rakumod",
"Pastes-Bin::Controller::Paste": "lib/Pastes-Bin/Controller/Paste.rakumod"
} }
} }

View file

@ -5,14 +5,15 @@ use DB::Migration::Simple;
use DBIish; use DBIish;
# Local libs # Local libs
#use Pastes-Bin::Controller::Paste; # Coming soon! #use Pastes-Bin::Controller::Paste;
use Pastes-Bin::Model::Paste;
# Logging # Logging
middleware &middleware-logger; middleware &middleware-logger;
advice &advice-logger; advice &advice-logger;
# Database stuff # Database stuff
my $dbh = DBIish.connect: my $*dbh = DBIish.connect:
'Pg', 'Pg',
:host<devbussy.swagg.net>, :host<devbussy.swagg.net>,
:database<pastes_bin>, :database<pastes_bin>,
@ -20,8 +21,12 @@ my $dbh = DBIish.connect:
password => prompt 'enter DB password: '; password => prompt 'enter DB password: ';
my $m = DB::Migration::Simple.new: my $m = DB::Migration::Simple.new:
:$dbh, :$*dbh,
:migration-file<migrations>, :migration-file<migrations>,
:verbose; :verbose;
$m.migrate: :version<1>; $m.migrate: :version<1>;
# No routes yet just prompt to 'fake it'
my $new-paste = prompt 'enter a new paste: ';
Pastes-Bin::Model::Paste.create: $new-paste;

View file

@ -0,0 +1,13 @@
use Humming-Bird::Core;
use Pastes-Bin::Model::Paste;
unit module Pastes-Bin::Controller::Paste;
get '/', -> $request, $response {
# No routes yet just prompt to 'fake it'
my $new-paste = prompt 'enter a new paste: ';
Pastes-Bin::Model::Paste.create: $new-paste;
$response.text('sent the paste!');
};

View file

@ -0,0 +1,8 @@
unit class Pastes-Bin::Model::Paste;
submethod create(Str $new-paste) {
$*dbh.execute(q:to/END_SQL/, $new-paste)
INSERT INTO pastes (paste_body)
VALUES (?);
END_SQL
}