Compare commits
No commits in common. "5848867423d5a86e4154a650902f8644592d3950" and "27b8036ff6365f381742579d784ef5941c07215a" have entirely different histories.
5848867423
...
27b8036ff6
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1 @@
|
|||
matabas-db/
|
||||
artifacts/
|
|
@ -1,12 +0,0 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module DBConfig where
|
||||
|
||||
import qualified Database.PostgreSQL.Typed as PG
|
||||
import Network.Socket (SockAddr(SockAddrUnix))
|
||||
|
||||
myPGDatabase :: PG.PGDatabase
|
||||
myPGDatabase = PG.defaultPGDatabase
|
||||
{ PG.pgDBAddr = Left ("localhost", "2137")
|
||||
, PG.pgDBUser = "matabasare"
|
||||
, PG.pgDBName = "matabas"
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
|
||||
import Control.Exception (bracket)
|
||||
import Control.Monad (void, unless)
|
||||
import Data.Int (Int32)
|
||||
import Data.Maybe (listToMaybe)
|
||||
import qualified Database.PostgreSQL.Typed as PG
|
||||
|
||||
import DBConfig
|
||||
|
||||
PG.useTPGDatabase myPGDatabase
|
||||
|
||||
data Ingredient = Ingredient Int32
|
||||
deriving (Eq)
|
||||
|
||||
createThing :: PG.PGConnection -> Ingredient -> IO ()
|
||||
createThing pg (Ingredient product_id) =
|
||||
void $ PG.pgExecute pg [PG.pgSQL|INSERT INTO ingredient (product_id) VALUES (${product_id})|]
|
||||
|
||||
main = bracket (PG.pgConnect myPGDatabase) PG.pgDisconnect $ \pg -> do
|
||||
let ing = Ingredient 10
|
||||
createThing pg ing
|
|
@ -1,9 +1,5 @@
|
|||
set -e
|
||||
|
||||
export PGPORT=2137
|
||||
export PGDATABASE=matabas
|
||||
export PGUSER=matabasare
|
||||
|
||||
log() {
|
||||
printf "\e[1m\e[38;5;87m==>\e[0m\e[1m %s%s\e[0m\n" "$1" "${2:-.}"
|
||||
}
|
||||
|
@ -16,7 +12,7 @@ exitHook() {
|
|||
log "Letar efter existerande brevekorresmapp"
|
||||
[ -d ./matabas-db ] || {
|
||||
log "Finns ej, skapar brevekorresmapp (./matabas-db)"
|
||||
pg_ctl initdb --pgdata=./matabas-db -o "--username=$PGUSER"
|
||||
pg_ctl initdb --pgdata=./matabas-db
|
||||
}
|
||||
|
||||
[ -f matabas-db/matabas.log ] && {
|
||||
|
@ -26,24 +22,39 @@ log "Letar efter existerande brevekorresmapp"
|
|||
}
|
||||
|
||||
log "Startar brevekorren"
|
||||
pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p $PGPORT -k /tmp"
|
||||
pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p 2137 -k /tmp"
|
||||
trap exitHook EXIT
|
||||
|
||||
log "Skapar matabas"
|
||||
createdb -p "$PGPORT" matabas 2>>./matabas-db/matabas.log || log "Matabasen finns, skriver ej över"
|
||||
createdb -p 2137 matabas 2>>./matabas-db/matabas.log || log "Matabasen finns, skriver ej över"
|
||||
|
||||
log "Ställer in schema.sql"
|
||||
psql -p "$PGPORT" "$PBDATABASE" < schema.sql
|
||||
|
||||
P="$PWD"
|
||||
clean() {
|
||||
log "Rensar byggnad"
|
||||
rm -rf artifacts
|
||||
}
|
||||
|
||||
build() {
|
||||
source "$P/buildScripts/build.sh"
|
||||
log "Försvensknar miljön"
|
||||
_cargo() {
|
||||
cuh="$1"
|
||||
shift
|
||||
case "$cuh" in
|
||||
kör|spring)
|
||||
cargo run "$@"
|
||||
;;
|
||||
ny)
|
||||
cargo new "$@"
|
||||
;;
|
||||
pröva)
|
||||
cargo test "$@"
|
||||
;;
|
||||
bygg)
|
||||
cargo build "$@"
|
||||
;;
|
||||
enna)
|
||||
cargo init "$@"
|
||||
;;
|
||||
*)
|
||||
echo "vafan gö du"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
alias 'last=_cargo'
|
||||
alias cargo=exit
|
||||
|
||||
log "Redo" "!"
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
set -e
|
||||
|
||||
mkdir -p artifacts
|
||||
|
||||
log "Kompilerar backend..."
|
||||
find backend -type f -and -name '*.hs' -print0 \
|
||||
| xargs -0 ghc -o artifacts/Main \
|
||||
-odir artifacts \
|
||||
-hidir artifacts \
|
||||
-tmpdir artifacts
|
||||
|
||||
log "Klar" "!"
|
||||
|
||||
set +e
|
|
@ -14,12 +14,8 @@
|
|||
default = pkgs.hello;
|
||||
};
|
||||
devShells.default = pkgs.mkShell {
|
||||
packages = [
|
||||
packages.default
|
||||
pkgs.postgresql_15_jit
|
||||
( pkgs.ghc.withPackages (ps: with ps; [ scotty postgresql-typed ]) )
|
||||
];
|
||||
shellHook = builtins.readFile ./buildScripts/devShellHook.sh ;
|
||||
packages = [ packages.default pkgs.postgresql_15_jit pkgs.cargo ];
|
||||
shellHook = builtins.readFile ./build/devShellHook.sh ;
|
||||
};
|
||||
}
|
||||
) // {
|
||||
|
|
11
schema.sql
11
schema.sql
|
@ -1,11 +0,0 @@
|
|||
CREATE TABLE IF NOT EXISTS ingredient
|
||||
( product_id INTEGER NOT NULL PRIMARY KEY -- https://handlaprivatkund.ica.se/stores/1004247/api/v4/products/bop?retailerProductId=...
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ingredient_data
|
||||
( product_id INTEGER REFERENCES ingredient(product_id)
|
||||
, name TEXT NOT NULL
|
||||
, cost_per_kg REAL NOT NULL
|
||||
, cost_per_unit REAL NOT NULL
|
||||
, image BYTEA NOT NULL
|
||||
);
|
Loading…
Reference in New Issue
Block a user