TIL: Sqlite Foreign Key Support (with Go)

Using foreign key constraints with SQL databases is very common. You can use those constrains to model relationships between tables. Here is an example: CREATE TABLE artist( artistid INTEGER PRIMARY KEY, artistname TEXT ); CREATE TABLE track( trackid INTEGER, trackname TEXT, trackartist INTEGER REFERENCES artist(artistid) -- Must map to an artist.artistid! ); Sqlite is a small and self-contained implementation of SQL. SQLite databases are used in production all around the world.
Read more →

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 code My 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 →

Setup a Postgres Database With Docker Compose

Adding a Postgres database to an existing service is fairly straightforward with docker-compose. Create a Dockerfile for your main service. For example, here’s a simple Docker container with Node: FROMnode:12.14.0-alpine3.9ENV NPM_CONFIG_PREFIX=/home/node/.npm-globalRUN npm install npm@latest -g --silentWORKDIR/opt/appCOPY package*.json /opt/app/RUN npm install --no-optional && npm cache clean --forceENV PATH /opt/app/node_modules/.bin:$PATHENV PATH=$PATH:/home/node/.npm-global/binARG NODE_ENV=production ENV NODE_ENV $NODE_ENVARG PORT=3000 ENV PORT $PORTEXPOSE$PORT 8229 8230COPY . .CMD ["npm", "run", "watch"]The Dockerfile starts from the official Node container, updates npm globally, installs the necessary packages, and runs an npm command (as root user in development mode).
Read more →

Docker Compose, Postgres and Travis CI

Today I tried to set up a dockerized Flask app with Postgres database with Travis CI. It shouldn’t have been difficult because I followed a tutorial. Setup Here is the docker-compose.yml: version: '3.7' services: users: build: context: ./services/users dockerfile: Dockerfile volumes: - './services/users:/usr/src/app' ports: - 5001:5000 environment: - FLASK_ENV=development - APP_SETTINGS=project.config.DevelopmentConfig - DATABASE_URL=postgres://postgres:postgres@users-db:5432/users_dev - DATABASE_TEST_URL=postgres://postgres:postgres@users-db:5432/users_test depends_on: - users-db users-db: build: context: ./services/users/project/db dockerfile: Dockerfile ports: - 5435:5432 environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres nginx: build: context: .
Read more →

Run PostgreSQL in a Docker Container

I try to learn something new every day, and I find it surprising what cool things you can do with technology. Today I learned that you could run a PostgreSQL database in a docker container. I was doing a Phoenix tutorial by Alvise Susmel. The article shows you how to create a Phoenix app which can handle user uploads and is an interesting piece in itself. But I also like the idea of running the database in Docker for local development.
Read more →

Sign up for the newletter!

powered by Buttondown