<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: kacorvus</title>
    <description>The latest articles on DEV Community by kacorvus (@kacorvus).</description>
    <link>https://dev.to/kacorvus</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1126644%2F7a70f8ee-4ed5-482f-a947-230bab72107e.png</url>
      <title>DEV Community: kacorvus</title>
      <link>https://dev.to/kacorvus</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kacorvus"/>
    <language>en</language>
    <item>
      <title>Exploring Database Interaction in elm-pages-v3 (nextjs/remix for elm)</title>
      <dc:creator>kacorvus</dc:creator>
      <pubDate>Tue, 25 Jul 2023 22:09:00 +0000</pubDate>
      <link>https://dev.to/kacorvus/exploring-elm-pages-v3-full-stack-elm-2in9</link>
      <guid>https://dev.to/kacorvus/exploring-elm-pages-v3-full-stack-elm-2in9</guid>
      <description>&lt;p&gt;Let's examine the persistence in the TODO app example (&lt;a href="https://github.com/dillonkearns/elm-pages/tree/master/examples/todos"&gt;https://github.com/dillonkearns/elm-pages/tree/master/examples/todos&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Overall project structure
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QwLnkwxe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/afw8630o4ehbc2xv73oi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QwLnkwxe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/afw8630o4ehbc2xv73oi.png" alt="Image description" width="580" height="1356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;app/Route/&lt;/code&gt; files - one per page, has &lt;code&gt;pages&lt;/code&gt;, &lt;code&gt;data&lt;/code&gt;, and &lt;code&gt;view&lt;/code&gt; functions; &lt;code&gt;pages&lt;/code&gt; runs at build time (or on server); &lt;code&gt;data&lt;/code&gt; runs at build time (or on server); &lt;code&gt;view&lt;/code&gt; runs at build time (or on server) and on client (e.g. Visibility__.elm, Login.elm)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;data&lt;/code&gt; function can refer to &lt;code&gt;Backend.Custom&lt;/code&gt; tasks, which call out to functions exposed from local node js libraries. In particular, there is a &lt;code&gt;custom-backend-task.ts&lt;/code&gt; file which defines functions wrapping prisma db calls.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;app/&lt;/code&gt; files contains sitewide utilities like layout, menu messages, and global state&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;prisma/schema.prisma&lt;/code&gt; defines the database schema&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;src/*&lt;/code&gt; contains local elm libraries of functions that route modules and others can use. elm-pages-v3 recommends using &lt;code&gt;app&lt;/code&gt; for well known files required by the framework, and using &lt;code&gt;src&lt;/code&gt; for additional elm source code&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Interaction with backend persistence
&lt;/h2&gt;

&lt;p&gt;reads&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Receive any necessary parameters as data from front end, encode as a parameter object and send to backend custom functions. (&lt;code&gt;Backend.Custom.run "getTodosBySession" (Encode.string parsedSession) resultDecoder&lt;/code&gt; where &lt;code&gt;parsedSession&lt;/code&gt; is the parameter in this case.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The custom backend function receives arguments, runs call, responds with result.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The response is decoded back to elm types, using the &lt;code&gt;resultDecoder&lt;/code&gt;. The result is used building out a &lt;code&gt;Data&lt;/code&gt; instance and eventually invoking &lt;code&gt;Server.Response.render&lt;/code&gt; with this &lt;code&gt;Data&lt;/code&gt; instance.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;writes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;something triggers an update action, which reaches &lt;code&gt;performAction&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;receive data from action, encode it and other arguments to send to backend custom function (&lt;code&gt;BackendTask.Custom.run "createTodo" (Encode.object [ ( "sessionId", sessionId |&amp;gt; Encode.string ) ] ) noopDecoder&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the custom backend function receives arguments, runs call &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the response is decoded to elm types, which results in no value in this case, and then &lt;code&gt;Server.Response.render&lt;/code&gt; with a populated &lt;code&gt;ActionData&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>elm</category>
      <category>elmpagesv3</category>
      <category>webdev</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
