<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ayodeji Ilori on Medium]]></title>
        <description><![CDATA[Stories by Ayodeji Ilori on Medium]]></description>
        <link>https://medium.com/@ayojava?source=rss-bef893cc036b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*j4tfeKQr3giOoicNv0FnnA.jpeg</url>
            <title>Stories by Ayodeji Ilori on Medium</title>
            <link>https://medium.com/@ayojava?source=rss-bef893cc036b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 04:01:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ayojava/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Introduction To Slick — Part 4 (Joins )]]></title>
            <link>https://medium.com/@ayojava/introduction-to-slick-part-4-joins-6ba043758704?source=rss-bef893cc036b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ba043758704</guid>
            <dc:creator><![CDATA[Ayodeji Ilori]]></dc:creator>
            <pubDate>Tue, 26 May 2020 00:34:53 GMT</pubDate>
            <atom:updated>2020-05-26T00:34:53.242Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction To Slick — Part 4 (Joins )</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*4v7UMfAkYIjLEEzYJo9tYA.jpeg" /></figure><p>This is a continuation of my earlier post : <a href="https://medium.com/@ayojava/introduction-to-slick-part-3-writing-queries-e548b04501d6">Introduction To Slick Part -3</a> . In this series we would be looking at JOINS .Joins are used to combine two different tables or queries into a single query. Below is the schema for the tables we would be using . The EmployeeProject Table has a Foreign Key each to both tables ( Employee Table and Project Table )</p><p><em>NB Follow the instructions on the ReadMe.md of the project link on gitlab </em><a href="https://gitlab.com/ayojava/projslick"><em>projSlick</em></a><em> so as to populate the db.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ngAJqMDz1PUD6Di5z7_Nkw.png" /><figcaption>Schema ( Employee Table , Project Table , Employee Project Table )</figcaption></figure><p>Possible JOINS include : Inner Join , JoinLeft , JoinRight , JoinFull and they have the same definition as their sql counterparts.</p><p>There are two different ways of writing joins: <em>Applicative</em> and <em>monadic</em>.</p><p>Monadic Joins are created using FlatMap . It joins queries into a single tuple consisting of individual results . This style also allows for navigation over foreign key relationships or use of equivalent columns with same values .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3155113904113274166b61b42072ae71/href">https://medium.com/media/3155113904113274166b61b42072ae71/href</a></iframe><p>Applicative Joins is where we explicitly write the JOIN statement in code . In Applicative Joins each join results in a query of tuples , with successive joins resulting in nested tuples .so Pattern matching is used to extract the required values or add a filter to choose which records are required.</p><p>In cases of either Left Outer Join or Right Outer Join , if their are no matching records on the right or left as the case may be , NULL values are returned , so Slick will lift those possible NULL values into OPTION</p><p>In Full Outer Join , both sides of the Join are lifted to an Option . If at least one element on either side matches the other side , all matching elements are returned as Some , otherwise a Single None row is returned.</p><p>Lastly, Cross Joins are obtained when we omit the “on” condition for any Join , JoinLeft, JoinRight . The record displayed will include every row from both tables .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9595d67f990456bf0285d2ac988f711e/href">https://medium.com/media/9595d67f990456bf0285d2ac988f711e/href</a></iframe><p>The source code for this project can be found on : <a href="https://gitlab.com/ayojava/projslick.git">https://gitlab.com/ayojava/projslick.git</a> . Although the source code is much explicit .</p><p>Other resources you can check out :</p><p>1: Scala Slick Documentation : <a href="http://scala-slick.org/docs/">http://scala-slick.org/docs/</a></p><p>2 : Essential Slick 3 pdf : <a href="http://underscore.io/books/essential-slick/">http://underscore.io/books/essential-slick/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ba043758704" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Slick — Part 3 ( Writing Queries )]]></title>
            <link>https://medium.com/@ayojava/introduction-to-slick-part-3-writing-queries-e548b04501d6?source=rss-bef893cc036b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e548b04501d6</guid>
            <dc:creator><![CDATA[Ayodeji Ilori]]></dc:creator>
            <pubDate>Sun, 16 Feb 2020 15:34:18 GMT</pubDate>
            <atom:updated>2020-02-16T15:36:35.372Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction to Slick -Part 3 ( Writing Queries )</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*a6LAFzvQBhvjECeXjI-A0A.jpeg" /></figure><p>This is a continuation of my earlier post : <a href="https://medium.com/@ayojava/introduction-to-slick-part-2-de854a09ea56">Introduction To Slick — Part 2</a> . Thus far we have been able to create tables , store some records . In this series we would be writing queries to select data .</p><p>The simplest select query is the TableQuery generated from a Table, which is a subtype of a more general Query type that Slick uses to represent select ,update ,and delete queries .We would be using the StudentTable to demo all the examples .</p><p>1 : <strong>Select All Query</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/822e1830772346bd1467bd82d6c8918c/href">https://medium.com/media/822e1830772346bd1467bd82d6c8918c/href</a></iframe><p>2 : <strong>Filter</strong></p><p>Creates a query for a subset of rows . The parameter to filter is a function from an instance of StudentQueryTable to a value of type Rep[Boolean] representing a WHERE clause for our query:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14cb18d3a5339116b89b0d55adb9a873/href">https://medium.com/media/14cb18d3a5339116b89b0d55adb9a873/href</a></iframe><p>3 : <strong>Transforming Results</strong></p><p>The map method on a Query allows us to select specific columns for inclusion in the results. The columns that are retrieved will be those available for filtering . So it is recommended that the “map” function be called as the final step after all operations have been applied.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a37b3b722d59b6bb1c2794a8de661859/href">https://medium.com/media/a37b3b722d59b6bb1c2794a8de661859/href</a></iframe><p>4 : <strong>Sort</strong></p><p>The function allows to sort by single or multiple columns in ascending or descending order.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/baa16f6a579f843612d068115b5b30f5/href">https://medium.com/media/baa16f6a579f843612d068115b5b30f5/href</a></iframe><p>5 : <strong>Aggregates</strong> : eg min, max, avg , sum</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a486e8bd9516b1388269bc1cc02e1e6/href">https://medium.com/media/1a486e8bd9516b1388269bc1cc02e1e6/href</a></iframe><p>My next post will be on Joins …..</p><p>To be contd …..</p><p>The source code for this project can be found on : <a href="https://gitlab.com/ayojava/projslick.git">https://gitlab.com/ayojava/projslick.git</a> . Although the source code is much explicit .</p><p>Other resources you can check out :</p><p>1: Scala Slick Documentation : <a href="http://scala-slick.org/docs/">http://scala-slick.org/docs/</a></p><p>2 : Essential Slick 3 pdf : <a href="http://underscore.io/books/essential-slick/">http://underscore.io/books/essential-slick/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e548b04501d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction To Slick -Part 2]]></title>
            <link>https://medium.com/@ayojava/introduction-to-slick-part-2-de854a09ea56?source=rss-bef893cc036b------2</link>
            <guid isPermaLink="false">https://medium.com/p/de854a09ea56</guid>
            <dc:creator><![CDATA[Ayodeji Ilori]]></dc:creator>
            <pubDate>Tue, 21 Jan 2020 18:18:31 GMT</pubDate>
            <atom:updated>2020-01-22T09:14:45.272Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a continuation of my earlier post <a href="https://medium.com/@ayojava/introduction-to-slick-part-1-8285d04a1211">Introduction To Slick -1 </a>. In the earlier post, we were able to connect to a mysql database , map our tables to scala case class and TableQuery Class. The create statements result in a DBIO[Unit] when run against the database and tables are created.</p><p>In this post we would be mapping relationships between tables eg Many To Many relationship using a join-table modelled as another case class. The tables will be :</p><ul><li>Employee Table : This table stores the details of an Employee . This stores the firstName , lastName , gender , employeeLevel(Junior, Senior , Management) , resumptionDate , id (primaryKey)</li><li>Project Table : This table stores the information about Projects allocated to employees such as projectName, startDate , project Status(Pending, Ongoing, Completed, Paused) ,id (primaryKey)</li><li>EmployeeProject Table : This stores the relationship between Employee and assigned Project. An Employee can be working on “n” projects conversely A Project can be assigned to “n” Employees . This implies that their will be a foreign key mapping to the Employee and Project Tables respectively i:e employeeId , projectId and (employeeId,projectId) as primaryKey.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LPUvX1y-ZxWsrYr6j0Mffg.png" /><figcaption>Database Schema</figcaption></figure><p>Lets begin : First we model case class for the tables</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d0edb171aeaf5305a4df8a07010d75e/href">https://medium.com/media/3d0edb171aeaf5305a4df8a07010d75e/href</a></iframe><p>Things to Note :</p><p>1- Primary keys are modelled as Value classes which serves as a compile-time wrapper around a value (Long) . To do this in slick, we would need “MappedTo” Trait to get a macro-generated implicit ColumnType for free. This prevents using the primary key of another class unknowingly during a search thereby producing a wrong result .(We would see this when we move to writing queries for the database)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1da60dada5f4a79a05a7da57a639d1be/href">https://medium.com/media/1da60dada5f4a79a05a7da57a639d1be/href</a></iframe><p>2- We introduced custom types “ProjectStatus” and “ EmployeeLevel” which we want mapped to [ PN , ON , CM , PS ] for ProjectStatus ; [ Junior , Senior , Management ] for EmployeeLevel in the database . We would need a custom columnType to manage the mapping .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64bbcb49109cc17b7aa989f34675c403/href">https://medium.com/media/64bbcb49109cc17b7aa989f34675c403/href</a></iframe><p>With this done , we can now model the Table</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6dcbbbda8b1216c7e3ceb86d857309f/href">https://medium.com/media/e6dcbbbda8b1216c7e3ceb86d857309f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20ca04f2c5f02aec8ea03a152fa40179/href">https://medium.com/media/20ca04f2c5f02aec8ea03a152fa40179/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a557a14f8f48f485d7fadac1fdaa2e49/href">https://medium.com/media/a557a14f8f48f485d7fadac1fdaa2e49/href</a></iframe><p>Note the EmployeeProjectTable , we defined a foreign key mapping to the EmployeeTable and ProjectTable . furthermore we defined a compound Primary key using both columns.</p><p>We would execute the previous ddl statements as before to create the new tables .</p><p>My next post will be on running queries against the schema using slick …..</p><p>To be contd …..</p><p>The source code for this project can be found on : <a href="https://gitlab.com/ayojava/projslick.git">https://gitlab.com/ayojava/projslick.git</a> . Although the source code is much explicit .</p><p>Other resources you can check out :</p><p>1: Scala Slick Documentation : <a href="http://scala-slick.org/docs/">http://scala-slick.org/docs/</a></p><p>2 : Essential Slick 3 pdf : <a href="http://underscore.io/books/essential-slick/">http://underscore.io/books/essential-slick/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de854a09ea56" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction To Slick Part 1]]></title>
            <link>https://medium.com/@ayojava/introduction-to-slick-part-1-8285d04a1211?source=rss-bef893cc036b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8285d04a1211</guid>
            <category><![CDATA[slick]]></category>
            <category><![CDATA[scala]]></category>
            <dc:creator><![CDATA[Ayodeji Ilori]]></dc:creator>
            <pubDate>Sat, 04 Jan 2020 17:24:42 GMT</pubDate>
            <atom:updated>2020-01-06T11:36:08.467Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction To Slick — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*a6LAFzvQBhvjECeXjI-A0A.jpeg" /></figure><p>A while ago , I decided to start learning <a href="https://www.scala-lang.org/">scala</a> and came across Slick . According to the documentation , Slick is a Scala library for accessing relational databases using an interface similar to the Scala collections library.</p><p>Initially I had issues understanding the concepts behind Slick , since I was coming from an ORM background (Hibernate , JPA) , however I can say its beginning to make sense bit by bit .</p><p>In this blog(and a series of others) , I will be explaining with examples how to use Slick. So let’s start.</p><p><strong>Requirements : </strong>Intellij IDE , MysqlServer 8.0 (you could run this in a docker container, but you would need to expose the ports so that Slick can connect to the db)</p><p><strong>Setting Up The Project :</strong></p><p>Create a new sbt project in IntelliJ go to: File &gt; New &gt; Project, then select sbt and click Next, let’s call our project projSlick. The IDE would download some dependencies if this is your first time , on completion of the process, open the sbt build file build.sbt .</p><p>This is where we would add the minimum dependencies required for the project</p><pre><em>name </em>:= &quot;projslick&quot;<br><br><em>version </em>:= &quot;0.1&quot;<br><br><em>scalaVersion </em>:= &quot;2.13.1&quot;<br><br><br><em>libraryDependencies </em>++= <em>Seq</em>(<br>  &quot;com.typesafe.slick&quot; %% &quot;slick&quot; % &quot;3.3.2&quot;,<br><br>  &quot;org.slf4j&quot; % &quot;slf4j-nop&quot; % &quot;1.7.29&quot;,<br>  <br>  &quot;mysql&quot; % &quot;mysql-connector-java&quot; % &quot;8.0.18&quot;,<br><br>  &quot;com.typesafe.slick&quot; %% &quot;slick-hikaricp&quot; % &quot;3.3.2&quot;,<br><br>  &quot;org.scalatest&quot; %% &quot;scalatest&quot; % &quot;3.0.8&quot; % &quot;test&quot;<br>)</pre><p>In the above, the libraries are downloaded from a set of predefined repositories for slick 3, mysql driver , slf4j , scalatest.</p><p>Next, we need to specify the configuration parameters that will allow our application to connect to the mysql Database . This configuration is placed in the src/main/resources/application.conf (create it if it doesn’t exist) .</p><pre>// Configuration for mysql database<br>// url : To access mysqlDB . NB you need to create a schema called &#39;slickdb&#39;<br>// user : user to connect to mysql<br>// password : password of user<br>// driver : mysql driver class<br><br>mysqlDB = {<br>  url = &quot;jdbc:mysql://localhost:3306/slickdb?useUnicode=true&amp;characterEncoding=UTF-8&amp;autoReconnect=true&quot;<br>  user=&quot;root&quot;<br>  password=&quot;&quot;<br>  driver = com.mysql.cj.jdbc.Driver<br>  connectionPool = disabled<br>  keepAliveConnection = true<br>}</pre><p>The syntax used is from typsafeconfig library. With this done, we are ready to move to actual code.</p><p><strong>Creating Database Tables</strong></p><p>I must confess that this initially was a bit confusing. I had thought you will need to annotate your case classes and slick would automatically generate the Tables like ORM’s .</p><p>However reading the documentation , helped to clear my doubts. you can check it out here <a href="https://scala-slick.org/doc/3.3.1/orm-to-slick.html">Coming from ORM to Slick</a> .</p><p>ORMs usually provide built-in, hard-coded support for 1-to-many and many-to-many relationships. They can be set up centrally in the configuration however Slick allows you to easily implement arbitrary use cases yourself. In other to have a good understanding of different mapping types, we would have separate examples for single Table , one-to-many Mapping , Many-To-Many Mapping.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9bdbd587283fa0e3692e3ccc605aa90/href">https://medium.com/media/e9bdbd587283fa0e3692e3ccc605aa90/href</a></iframe><p>From the above , you can represent database tables as a Scala Case class or Scala Type and define a Table object which corresponds to our database table and tells Slick how to map back and forth between database data and instances of our case class.</p><p>The StudentTable defines 6 columns : id , firstName, lastName ,middleName ,emailAddress , age . It defines the names and types of these columns and any constraints on them at the database level.eg</p><ul><li><strong>id</strong> : column of Long values , auto-incrementing , primary key</li><li><strong>firstName , lastName</strong> : column of String values , cannot be NULL , length -512</li><li><strong>middleName</strong> : column of String values but can be NULL</li><li><strong>emailAddress</strong> : column of String values , cannot be NULL</li><li><strong>age</strong> : column of Int values , cannot be NULL</li></ul><p>The <strong>*</strong> method provides a default projection that maps between columns in the table and instances of our case class. Slick’s <strong>mapTo</strong> macro creates a two-way mapping between the six columns and the six fields in Student case class.</p><p>The TableQuery’s schema method creates DDL (data definition language) objects with the database-specific code for creating and dropping tables and other database entities.</p><p>Multiple DDL values can be combined with ++ to allow all entities to be created and dropped in the correct order, even when they have circular dependencies on each other.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd58fa5ab8f75e2a24f3ddd314405b7d/href">https://medium.com/media/dd58fa5ab8f75e2a24f3ddd314405b7d/href</a></iframe><p>The result of this <strong><em>studentTable.schema.create</em></strong> expression is a DBIO[Unit]. This is an object representing a DB action that, when run, completes with a result of type Unit. Anything we run against a database is a DBIO[T] (or a DBIOAction, more generally).</p><p>Other options are createIfNotExists, dropIfExists, drop and truncate methods produce the Actions for executing the DDL statements.To safely create and drop tables use the methods createIfNotExists and dropIfExists .</p><p>My next post will be on mapping relationships amongst tables and representing it in slick .</p><p>To be contd …..</p><p>The source code for this project can be found on : <a href="https://gitlab.com/ayojava/projslick.git">https://gitlab.com/ayojava/projslick.git</a> . Although the source code is much explicit .</p><p>Other resources you can check out :</p><p>1: Scala Slick Documentation : <a href="http://scala-slick.org/docs/">http://scala-slick.org/docs/</a></p><p>2 : Essential Slick 3 pdf : <a href="http://underscore.io/books/essential-slick/">http://underscore.io/books/essential-slick/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8285d04a1211" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>