<?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: Srimanta Narayan Ghosh</title>
    <description>The latest articles on DEV Community by Srimanta Narayan Ghosh (@ghosh_srimanta).</description>
    <link>https://dev.to/ghosh_srimanta</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4236216%2Fd9752d8e-a649-4c1c-8807-f5cbde66bf2f.png</url>
      <title>DEV Community: Srimanta Narayan Ghosh</title>
      <link>https://dev.to/ghosh_srimanta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ghosh_srimanta"/>
    <language>en</language>
    <item>
      <title>I make 60-second CS explainer videos with no video editor: one HTML file, headless Chrome and ffmpeg</title>
      <dc:creator>Srimanta Narayan Ghosh</dc:creator>
      <pubDate>Mon, 16 Nov 2026 07:21:17 +0000</pubDate>
      <link>https://dev.to/ghosh_srimanta/i-make-60-second-cs-explainer-videos-with-no-video-editor-one-html-file-headless-chrome-and-ffmpeg-12j0</link>
      <guid>https://dev.to/ghosh_srimanta/i-make-60-second-cs-explainer-videos-with-no-video-editor-one-html-file-headless-chrome-and-ffmpeg-12j0</guid>
      <description>&lt;p&gt;I run &lt;a href="https://csip12.in" rel="noopener noreferrer"&gt;csip12.in&lt;/a&gt;, a small free study site for CBSE Class 11 and 12 Computer Science students in India. Students asked for short videos, so this month I started making 60-second explainers for topics like circuit switching and packet switching.&lt;/p&gt;

&lt;p&gt;I do not own a video editor and I did not want to learn one. Instead, each video is a web page that knows how to draw any moment of itself, and a script that takes 30 photos of it per second. Here is how it works and what went wrong along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The video is a pure function of time
&lt;/h2&gt;

&lt;p&gt;The whole video is one HTML file at 1080×1920. It has a fixed layout (title, a speech-bubble caption, an SVG area for the animation, progress dots) and one important function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;DUR&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;START&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// which scene&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;lt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="no"&gt;START&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                                          &lt;span class="c1"&gt;// time inside it&lt;/span&gt;
  &lt;span class="n"&gt;art&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;SCENES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;DUR&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                            &lt;span class="c1"&gt;// SVG string&lt;/span&gt;
  &lt;span class="n"&gt;cap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;CAPTIONS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each scene is a function &lt;code&gt;(localTime, duration) =&amp;gt; svgString&lt;/code&gt;. There is no &lt;code&gt;requestAnimationFrame&lt;/code&gt;, no CSS transitions, no state carried from one frame to the next. Every frame is computed from &lt;code&gt;t&lt;/code&gt; alone.&lt;/p&gt;

&lt;p&gt;That one rule is what makes the rest easy. I can jump to second 37.4 and see exactly what that frame will look like. I can render frames out of order, or render one still per scene to check the layout before spending ten minutes on a full capture.&lt;/p&gt;

&lt;p&gt;The animations are just small helpers on top of that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;clamp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// pop(lt, at): 0 before `at`, then a quick overshoot up to 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A packet moving from router R1 to R2 is &lt;code&gt;lerp(x1, x2, ease(clamp((lt - 1.2) / 0.8)))&lt;/code&gt;. A label appearing at 2.5 s is &lt;code&gt;scale = pop(lt, 2.5)&lt;/code&gt;. Once you have five or six of these, building a scene goes surprisingly fast.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Taking the photos
&lt;/h2&gt;

&lt;p&gt;A Python script starts Chrome headless with &lt;code&gt;--remote-debugging-port&lt;/code&gt;, opens the page over the DevTools protocol, and then loops:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;TOTAL&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;FPS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Runtime.evaluate'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expression&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;'render({i / FPS})'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;shot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Page.captureScreenshot'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'jpeg'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quality&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;92&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;'frames/f{i:05d}.jpg'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shot&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'data'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details mattered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fonts.&lt;/strong&gt; Before the first frame, I wait on &lt;code&gt;document.fonts.ready&lt;/code&gt; and print which font families actually loaded. A fallback font in frame 1 and the real font in frame 40 looks like a glitch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Window size.&lt;/strong&gt; &lt;code&gt;Emulation.setDeviceMetricsOverride&lt;/code&gt; with 1080×1920 and &lt;code&gt;deviceScaleFactor: 1&lt;/code&gt;, so the screenshot is exactly one video frame with no scaling.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A 60-second video is 1,800 screenshots. On my laptop that takes a few minutes, which is fine.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Timing comes from the voice, not the other way round
&lt;/h2&gt;

&lt;p&gt;I write the narration first, one line per scene, and generate each line with a text-to-speech model running locally. Then the build script:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;trims the silence at both ends of every line with ffmpeg's &lt;code&gt;silenceremove&lt;/code&gt; (run forwards, reversed, and forwards again so it trims the end too),&lt;/li&gt;
&lt;li&gt;measures each trimmed clip with &lt;code&gt;ffprobe&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;sets each scene's duration to the line's length plus 0.85 s of breathing room,&lt;/li&gt;
&lt;li&gt;writes those durations into a copy of the HTML file before capturing.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So if I rewrite a sentence and it gets longer, the scene simply gets longer. Nothing needs to be re-timed by hand.&lt;/p&gt;

&lt;p&gt;The audio is one &lt;code&gt;ffmpeg -filter_complex&lt;/code&gt;: each voice line is delayed to its scene start with &lt;code&gt;adelay&lt;/code&gt;, everything is mixed with &lt;code&gt;amix&lt;/code&gt;, a quiet background track is added at 8% volume, and &lt;code&gt;loudnorm=I=-14&lt;/code&gt; brings the result to the loudness that YouTube and Facebook expect. The background music is also generated, a four-chord loop of sine waves written with NumPy, so there is nothing to license.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Things that bit me
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Stale frames.&lt;/strong&gt; I once shortened a video and the output came out longer than before. The capture had written frames 0–1,850 into a folder that still held frames up to 1,950 from the previous, longer render, and ffmpeg's &lt;code&gt;f%05d.jpg&lt;/code&gt; input happily used all of them. The build now deletes the frames folder before every capture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Checking audio quality without listening to all of it.&lt;/strong&gt; Local TTS on a 4 GB GPU sometimes returns a take that is just a hum or hiss. Instead of listening to every take, I render a tiny spectrogram for each line (&lt;code&gt;showspectrumpic&lt;/code&gt;, 0–4 kHz). Real speech shows clear stacked harmonic stripes, and a bad take shows flat horizontal bars or uniform noise. I glance at ten small images and re-generate only the bad lines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ffmpeg crashing on contact sheets.&lt;/strong&gt; I wanted a grid of one still per scene to review layouts at a glance. &lt;code&gt;hstack&lt;/code&gt;/&lt;code&gt;xstack&lt;/code&gt; with a dozen inputs crashed ffmpeg on Windows with a heap error, so I tile the stills with Pillow instead. It is five lines of code and has never failed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Text overflow.&lt;/strong&gt; SVG text does not wrap and does not complain. A table cell like "Store &amp;amp; forward" at font size 38 quietly ran over its box. The only reliable check was the contact sheet: render the stills and look.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why not just use a video editor?
&lt;/h2&gt;

&lt;p&gt;For one video, an editor is faster. For a series, this approach wins: every video shares the same layout and helpers, so a new topic means writing about ten scene functions and ten sentences. Changing the brand colour or the caption font across all videos is a single line of CSS. And because the video lives in plain text files, I can keep old versions and see exactly what changed between them.&lt;/p&gt;

&lt;p&gt;The first one, on circuit switching, is here: &lt;a href="https://youtube.com/shorts/huqvXe6f_H8" rel="noopener noreferrer"&gt;Circuit Switching in 60 seconds&lt;/a&gt;. The notes it is based on are on &lt;a href="https://csip12.in" rel="noopener noreferrer"&gt;csip12.in&lt;/a&gt;, and I would be glad to hear from anyone who has built something similar, especially about speeding up the capture loop.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>python</category>
      <category>ffmpeg</category>
      <category>education</category>
    </item>
    <item>
      <title>I built a MySQL practice lab on SQLite in the browser. Here is where the two disagree</title>
      <dc:creator>Srimanta Narayan Ghosh</dc:creator>
      <pubDate>Tue, 10 Nov 2026 03:40:45 +0000</pubDate>
      <link>https://dev.to/ghosh_srimanta/i-built-a-mysql-practice-lab-on-sqlite-in-the-browser-here-is-where-the-two-disagree-p29</link>
      <guid>https://dev.to/ghosh_srimanta/i-built-a-mysql-practice-lab-on-sqlite-in-the-browser-here-is-where-the-two-disagree-p29</guid>
      <description>&lt;p&gt;I run a small free study site for CBSE Class 11 and 12 students in India. SQL is part of their syllabus, and the syllabus is written around MySQL. The problem: most students practise on a phone or a locked school computer, where installing MySQL is not an option.&lt;/p&gt;

&lt;p&gt;So I built a SQL lab that runs fully in the browser. It uses &lt;a href="https://github.com/sql-js/sql.js" rel="noopener noreferrer"&gt;sql.js&lt;/a&gt; (SQLite compiled to WebAssembly) with a translation layer on top, so that students type MySQL and get MySQL-style answers. No server, no login.&lt;/p&gt;

&lt;p&gt;"SQLite is close enough to MySQL" turned out to be wrong in ways that matter to a beginner. Here are the gaps that cost me the most time.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. String comparison
&lt;/h2&gt;

&lt;p&gt;In MySQL, with the default collation, this finds &lt;code&gt;Amit&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'amit'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In SQLite it returns nothing, because text comparison is case-sensitive. A student who gets zero rows here will "learn" something that is false in their exam.&lt;/p&gt;

&lt;p&gt;Declaring text columns as &lt;code&gt;TEXT COLLATE NOCASE&lt;/code&gt; fixes column-to-literal comparisons, but not everything: function results and literal-to-literal comparisons lose the collation. I ended up adding &lt;code&gt;COLLATE NOCASE&lt;/code&gt; to string literals and &lt;code&gt;IN&lt;/code&gt; lists during translation as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. SQLite accepts almost anything in any column
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;roll&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'abc'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MySQL in strict mode rejects this with error 1366. SQLite happily stores the text in an INTEGER column. Since students are learning what data types mean, silent acceptance is the worst possible behaviour.&lt;/p&gt;

&lt;p&gt;The layer wraps every inserted or updated value in a converter function chosen from the column's declared MySQL type. The converter either returns a clean value or raises the MySQL error.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Missing functions, and two sql.js surprises
&lt;/h2&gt;

&lt;p&gt;MySQL functions such as &lt;code&gt;MID()&lt;/code&gt;, &lt;code&gt;DAYNAME()&lt;/code&gt;, &lt;code&gt;NOW()&lt;/code&gt; and &lt;code&gt;TRUNCATE()&lt;/code&gt; do not exist in SQLite, and a few that do exist behave differently. I registered my own versions with &lt;code&gt;db.create_function()&lt;/code&gt; under a prefix, and the translator rewrites calls to the prefixed names.&lt;/p&gt;

&lt;p&gt;Two things I did not expect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If your JavaScript function throws an &lt;code&gt;Error&lt;/code&gt; object, the message that reaches you from sql.js is empty. Throw a plain string and it comes through.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;db.export()&lt;/code&gt; gives you the database bytes, but a database loaded from them has none of your custom functions. I wanted students' tables to survive a page reload, so I save my own JSON dump of the schema and rows to &lt;code&gt;localStorage&lt;/code&gt; and rebuild from that.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Error messages are part of the lesson
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;no such function: MIDD&lt;/code&gt; is a fine message, but it is not what the student will see in the school lab. The layer maps SQLite errors onto MySQL ones:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR 1305 (42000): FUNCTION school.MIDD does not exist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same for unknown tables (1146), unknown columns (1054) and wrong argument counts (1582).&lt;/p&gt;

&lt;h2&gt;
  
  
  How I tested it
&lt;/h2&gt;

&lt;p&gt;I did not trust myself to remember MySQL behaviour, so I wrote about 200 statements covering the syllabus and ran each one both through the lab and through a real database server, then compared the outputs cell by cell. Every mismatch was either fixed or written down as a known limitation.&lt;/p&gt;

&lt;p&gt;Then I fuzzed it: around 6,300 broken or mutated statements. That found an infinite loop on an unclosed &lt;code&gt;USING (&lt;/code&gt; and a few crashes on half-typed statements such as a bare &lt;code&gt;INSERT INTO&lt;/code&gt;. Beginners type exactly that kind of thing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it still cannot do
&lt;/h2&gt;

&lt;p&gt;Stored procedures, triggers, user variables and multi-table &lt;code&gt;UPDATE&lt;/code&gt;/&lt;code&gt;DELETE&lt;/code&gt; are not supported. They are outside the school syllabus, so I left them out rather than fake them.&lt;/p&gt;

&lt;p&gt;If you want to try it, the lab is here: &lt;a href="https://csip12.in/sql-lab" rel="noopener noreferrer"&gt;csip12.in/sql-lab&lt;/a&gt;. It comes with a small sample database, and I would be glad to hear about any query where it disagrees with real MySQL.&lt;/p&gt;

</description>
      <category>sql</category>
      <category>sqlite</category>
      <category>webassembly</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
