Object-Relational Mapping: DBIx::Class::Schema::Loader | #2 Perl DBIx Tutorial
In this Perl programming tutorial, we will explore how to set up MySQL database using Docker and how to generate DBIx classes using DBIx::Class::Schema::Loader. Chapters: 00:00 Intro 01:00 Installing Docker 02:17 Starting MySQL container 04:54 Connecting to MySQL database 05:57 Starting PHPMyAdmin container 08:06 Applying SQL with test data 09:49 Installing DBIx::Class::Schema::Loader 11:53 Generating DBIx files with DBIx::Class::Schema::Loader Docker commands: - docker run --name mysql -p 3306:3306 -v ./mysql_data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password -d mysql:8.3.0 - docker run --name myphpadmin -d --link mysql:db -p 8080:80 phpmyadmin -- SQL TEST DATA DROP DATABASE IF EXISTS `notes`; CREATE DATABASE IF NOT EXISTS `notes`; USE `notes`; CREATE TABLE IF NOT EXISTS `user` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `username` VARCHAR(255) DEFAULT NULL, CONSTRAINT `unq__user__username` UNIQUE(`username`), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `note` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `user_id` INT UNSIGNED NOT NULL, `description` VARCHAR(255) DEFAULT NULL, `importance` INT NOT NULL DEFAULT 1, CONSTRAINT `fk__note__user_id` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE CASCADE ON DELETE CASCADE, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; INSERT INTO `user`(`username`) VALUES ('user1'); SET @last_inserted_user_id := LAST_INSERT_ID(); INSERT INTO `note`(`user_id`, `description`, `importance`) VALUES ( @last_inserted_user_id, 'Note 1 from user1', 1 ), ( @last_inserted_user_id, 'Note 2 from user1', 2 ), ( @last_inserted_user_id, 'Note 3 from user1', 3 ) ; INSERT INTO `user`(`username`) VALUES ('user2'); SET @last_inserted_user_id := LAST_INSERT_ID(); INSERT INTO `note`(`user_id`, `description`, `importance`) VALUES ( @last_inserted_user_id, 'Note 1 from user2', 1 ), ( @last_inserted_user_id, 'Note 2 from user2', 2 ), ( @last_inserted_user_id, 'Note 3 from user2', 3 ) ; -- END SQL TEST DATA Docs: https://metacpan.org/pod/DBIx::Class https://metacpan.org/pod/DBIx::Class::Row https://metacpan.org/pod/DBIx::Class::ResultSet https://metacpan.org/pod/DBIx::Class::Schema::Loader Tags: #Perl #PerlProgramming #CodingInPerl #PerlDevelopment
Download
0 formatsNo download links available.