SimpleBank Based on https://github.com/techschool/simplebank
https://hub.docker.com/_/postgres
- get image: docker pull {image}:{tag}
docker pull postgres:12-alpine
- start a container: docker run --name {container_name} -e {environment_variable} -p {host_ports:container_ports} -d {image}:{tag}
docker run --name postgres12 -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=root -d postgres:12-alpine
- connect to container: docker exec -it {container_name_or_id} {command} [args]
docker exec -it postgres12 /bin/sh
docker exec -it postgres12 psql -U root
Atomicity
Consistency
Isolation
Durability
database/sql: fast but mistakes cannot be caught until runtime
gorm: low code but slow on high load (gorm的运行速度比标准库慢3-5倍)
sqlx: fast & easy but mistakes cannot be caught until runtime
sqlc: automatic code generation, especially for Postgres
In Mysql:
select @@transaction_isolation
set session transaction isolation level {isolation_level}
In Postgres:
show transaction isolation level;
// only can set transaction level within trasaction
set transaction isolation level {isolation level}
isolation level:
- read uncommitted
- read committed: stop dirty read
- repeatable read(Mysql default): stop dirty read and unrepeatable read
- serializable: stop dirty read, unrepeated read and serialization anomaly(序列化异常)
In Postgres
- read uncommitted mode behaves like read committed.
- Using dependence detection
- default level: RC
In Mysql
- default level: RR
- Using locking mechanism
- Actions on the website
- Coding .yml file to decide steps
- install: https://github.com/golang/mock
- vi ~/.zshrc
- add export PATH=$PATH:~/go/bin
- source ~/.zshrc
- using which mockgen to make sure mockgen is valid.
{ALG}{Cost}{Salt}{Hash}
e.g. $2a$10$dGIJ4fEL7jKAzzddDuwGSe3o9mTcO/Tv.3XwJsbJZHXOhXrjr01ce
password -- bcrypt hash (cost, salt) --> hashed_password