Last active
April 13, 2020 23:14
-
-
Save megri/4cae937b638eb2df89b6f9f457df3734 to your computer and use it in GitHub Desktop.
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
override def run(args: List[String]): IO[ExitCode] = { | |
val databaseConfig = DatabaseConfig( | |
host = "localhost", | |
port = 5432, | |
username = "postgres", | |
database = "postgres", | |
password = None, | |
strategy = Strategy.SearchPath, | |
debug = true | |
) | |
migrate(databaseConfig) *> sessionPool(databaseConfig).use { pool => | |
val routes = { | |
val companyStorage = new company.CompanyDAO(pool) | |
val companyRoutes = new company.CompanyRoutes(companyStorage) | |
val categoryStorage = new category.CategoryDAO(pool) | |
val categoryRoutes = new category.CategoryRoutes(categoryStorage) | |
(companyRoutes.routes <+> categoryRoutes.routes) | |
}.orNotFound | |
BlazeServerBuilder[IO] | |
.bindHttp(8080, "0.0.0.0") | |
.withHttpApp(routes) | |
.serve | |
.compile | |
.drain | |
.as(ExitCode.Success) | |
} | |
} |
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
… tons of RowData(…) up here... | |
← RowData(List(Some(113), Some(26))) | |
ⓘ ← RowData(List(Some(112), Some(26))) | |
ⓘ ← CommandComplete(Select(1293)) | |
ⓘ ← ReadyForQuery(Idle) | |
ⓘ → Parse(statement_1, | |
ⓘ INSERT INTO company ( | |
ⓘ organization_number, | |
ⓘ name, | |
ⓘ description, | |
ⓘ email, | |
ⓘ category_id, | |
ⓘ municipality_id, | |
ⓘ street_address, | |
ⓘ postal_code, | |
ⓘ locality, | |
ⓘ phone_number, | |
ⓘ website_url | |
ⓘ ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) | |
ⓘ RETURNING * | |
ⓘ ,List(25, 25, 25, 25, 20, 20, 25, 25, 25, 25, 25)) | |
ⓘ → Flush | |
ⓘ ← ParseComplete | |
ⓘ → Describe(S, statement_1) | |
ⓘ → Flush | |
ⓘ ← ParameterDescription(List(25, 25, 25, 25, 20, 20, 25, 25, 25, 25, 25)) | |
ⓘ ← RowDescription(Field(organization_number, 25); Field(name, 25); Field(description, 25); Field(email, 25); Field(category_id, 20); Field(municipality_id, 20); Field(street_address, 25); Field(postal_code, 25); Field(locality, 25); Field(phone_number, 25); Field(website_url, 25)) | |
ⓘ → Bind(portal_2,statement_1,List(Some(123456-1234), Some(a name), Some(a description), Some(name@domain.com), Some(1), Some(2), Some(abc123), Some(12345), Some(some locality), Some(123456), Some(https://foobar.com))) | |
ⓘ → Flush | |
ⓘ ← BindComplete | |
ⓘ → Execute(portal_2,2) | |
ⓘ → Flush | |
ⓘ ← ErrorResponse(s -> public, n -> company_municipality_id_fkey, t -> company, F -> ri_triggers.c, M -> insert or update on table "company" violates foreign key constraint "company_municipality_id_fkey", V -> ERROR, L -> 2783, C -> 23503, R -> ri_ReportViolation, D -> Key (municipality_id)=(2) is not present in table "municipality"., S -> ERROR | |
ⓘ → Close(P,portal_2) | |
ⓘ → Flush |
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
val registerQuery = | |
sql""" | |
INSERT INTO company ( | |
organization_number, | |
name, | |
description, | |
email, | |
category_id, | |
municipality_id, | |
street_address, | |
postal_code, | |
locality, | |
phone_number, | |
website_url | |
) VALUES ($company) | |
RETURNING * | |
""".query(company.gimap[Company]) |
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
sessionPool.use { session => | |
session.prepare(registerQuery).use { ps => | |
ps.unique( | |
companyRegistration.organizationNumber.value ~ | |
companyRegistration.name.value ~ | |
companyRegistration.description.value ~ | |
companyRegistration.email.value ~ | |
companyRegistration.categoryId.value ~ | |
companyRegistration.municipalityId.value ~ | |
companyRegistration.streetAddress.value ~ | |
companyRegistration.postalCode.value ~ | |
companyRegistration.locality ~ | |
companyRegistration.phoneNumber.map(_.value) ~ | |
companyRegistration.websiteUrl.map(_.value) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment