This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS Users ( | |
id INTEGER PRIMARY KEY AUTOINCREMENT, | |
public_id TEXT UNIQUE NOT NULL, | |
fullname TEXT NOT NULL, | |
username TEXT UNIQUE NOT NULL, | |
description TEXT, | |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Concept 1: | |
# Elixir can spawn process to run functions. | |
spawn(fn -> | |
"Hello world!" | |
end) | |
# Concept 2: | |
# Elixir can send messages to other process, including the current IEX one. | |
# At the same time, it can stop the runtime and wait to recieve a message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Counter do | |
def new(state) do | |
spawn(Counter, :listener, [state]) | |
end | |
def arun(pid, args) do # Async run. | |
send(pid, {:arun, args}) | |
end | |
def srun(pid, args) do # Sync run. |