TIL: PostgreSQL Insert ID Only Works With id as Primary Key

I've created a database table for my PostgreSQL database with Nim: import db_postgres, os # some code proc setup*(database: Database) = database.db.exec(sql""" CREATE TABLE IF NOT EXISTS Url( shortcode SERIAL PRIMARY KEY, orig_url VARCHAR(255) NOT NULL ); """)# more codeMy primary key is shortcode as a SERIAL data type. That means the shortcode column automatically increments. I want to insert data into the database and return the generated ID for the row.
Read more →

Refactoring My Nim sqlite DB to Postgres

Today I've spent all my coding time on re-factoring my sqlite3 database to postgres. Nim and Jester (a web framework) ship with inbuilt sqlite3 features. I couldn't get them working within Docker. I know how to use Docker and Postgres. Plus, the wrapper library for Nim around SQL databases offers a consistent API. My re-factoring only needed minimal changes. The project is still in flux. And I have some annoying errors with Nim and SQL queries.
Read more →

Working on Nim URL Shortener With Docker

Read more →

Nim First Impressions

I've started dabbling in Nim some days ago. My experience level: I'm a self-taught hobby developer. No professional experience, but a lot of enthusiasm. I've created some toy applications, but nothing production-grade. I'm most familiar with JavaScript and React.js, but also know a bit of Clojure, Elixir, Python, and Reason. What is Nim? From the Nim website: Efficient, expressive, elegant Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula.
Read more →

Learning Progress Nim

I've finished chapter 3 of Nim in Action. I completed the terminal-based chat application. Learning Nim is fun, but there are still many concepts I'm unsure about. For example, I don't know how the memory model works. I started chapter 6 of the book, and I don't understand how to parse a file. Chapter 6 introduces parallelism, and I'm confused about locks. Still, I like that the book uses practical examples to teach concepts.
Read more →

TIL: Objects in Nim

Objects in Nim use the type constructor:

Type Definition type MusicTrack = object index: int title: string # (Mutable) Value var summer = MusicTrack(index: 1, title: "Summer in the City") That reminds me of Records in Reason:

/* Type definition */ type musicTrack = {index: int, title: string} /* Value */ let summerInTheCity = {index: 1, title: "Summer in the City"} In Nim, “An object is a value type, which means that when an object is assigned to a new variable all its components are copied as well.

Read more →

Reading “Nim in Action”

I'm currently working through the excellent book Nim in Action by Dominik Picheta. Nim looks like a promising and fresh language: Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. What I like about Nim is that it looks like Python, but it compiles to a dependency-free executable (C, C++, or JavaScript). The language is fairly small, but it allows for writing macros (meta-programming) like a Lisp.
Read more →

Setup Nim With Neovim

Use Neovim as your Nim IDE Why Nim? Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. 1 Nim resembles Python, but the language is significantly faster and statically compiled. Nim comes with meta-programming abilities (like a LISP). You can compile a Nim program into a stand-alone C binary that runs on every system.
Read more →