Developer Blog

Tipps und Tricks für Entwickler und IT-Interessierte

Elixir| Einstieg in Elixir und Phoenix

Installation

Erlang / Elixir

Unter Windows

Installationspakete unter Erlang / Downloads (Version 24.0) und Elixir / Downloads (Web Installer)

Erstellen einer ersten Anwendung

Anwendung mit dem Namen ‘app’ erstellen.

Als Vorlage wird ‘live’ werwendet. Diese vewendet Phoenix.LiveView und erleichter die Erstellung von Web Anwendungen.

mix phx.new --live app

Frontend erstellen

cd app
cd assets 
npm install 
node node_modules/webpack/bin/webpack.js --mode development

Datenbank-Instanz einrichten und starten

Elixir und Phoenix verwendet in der Standardeinstellung eine PostgreSQL Datenbanken.

Der einfachste Weg, eine lauffähige PostgrSQL Datenbank einzurichten, ist mit Hilfe von Docker.

Erstellen Sie hierzu einen Datei docker-compose.yml:

version: '3.5'

networks:
  postgres:
    name: ${POSTGRES_CONTAINER:-workshop_elixir_postgres}
    driver: bridge

volumes:
    postgres:
      name: postgres

services:
  postgres:
    container_name: ${POSTGRES_CONTAINER:-workshop_elixir_postgres}
    image: postgres
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-postgres}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
      PGDATA: /data/postgres

    volumes:
       - postgres:/data/postgres

    ports:
      - "5432:5432"

    networks:
      - postgres

    restart: unless-stopped

Starten Sie die Datenbank in einem eigenen Fenster mit dem nachfolgenden Kommando:

docker compose up
[+] Running 14/14
 - db Pulled
   - b4d181a07f80 Already exists
   - 46ca1d02c28c Pull complete
   - a756866b5565 Pull complete
   - 36c49e539e90 Pull complete
   - 664019fbcaff Pull complete 
   - 727aeee9c480 Pull complete
   - 796589e6b223 Pull complete
   - 6664992e747d Pull complete
   - 0f933aa7ccec Pull complete
   - 99b5e5d88b32 Pull complete
   - a901b82e6004 Pull complete
   - 625fd35fd0f3 Pull complete
   - 9e37bf358a5d Pull complete
[+] Running 1/1
 - Container elixis_postgres  Started
Attaching to elixis_postgres
elixis_postgres  | The files belonging to this database system will be owned by user "postgres".
elixis_postgres  | This user must also own the server process.
...
...
...
elixis_postgres  | 2021-07-12 15:01:08.042 UTC [1] LOG:  database system is ready to accept connections

Datenbanktabellen erstellen

Festlegen der Datenbank-Verbindungsparameter in der Datei config/dev.exs.

Wir verwenden dabie die gleichen Werte, die wir in der Datei docker-compose.yml verwendet haben:

POSTGRES_USERusername
POSTGRES_PASSWORDpassword
POSTGRES_DBdatabase
config :app, App.Repo,
  username: "root",
  password: "root",
  database: "playground",
  hostname: "localhost",
  show_sensitive_data_on_connection_error: true,
  pool_size: 10

Erstellen der Datenbank-Tabellen

mix ecto.create

Webserver starten

mix phx.server

Links

Elixir und das Web

Elixir und Datenbanken

  • Ecto – domain specific language for writing queries and interacting with databases Github

Tips zum Erlernen von Elixir

Screencasts

Übungen /Exercises

Bücher

Cobol | Get Started

Installation

Cobol

brew install gnu-cobol
cobc --version
cobc (GnuCOBOL) 2.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
Built     Oct 15 2019 14:14:21
Packaged  Sep 06 2017 18:48:43 UTC
C version "4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.8)"

First Steps

Create sample programm

Create Hello World programm hello_world.cob

HELLO * HISTORIC EXAMPLE OF HELLO WORLD IN COBOL
       IDENTIFICATION DIVISION.
       PROGRAM-ID. HELLO.
       PROCEDURE DIVISION.
           DISPLAY "HELLO, WORLD".
           STOP RUN.

Compile programm and build executable program

cobc -x hello_world.cob

Run programm

$ ./helloworld
HELLO, WORLD