-
Notifications
You must be signed in to change notification settings - Fork 0
persistence ok and zod on db entity #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GorlemZ
wants to merge
11
commits into
main
Choose a base branch
from
ts-step-5b
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
39a008d
persistence ok and zod on db entity
GorlemZ 6bed6eb
test fix
GorlemZ abe51db
closing db connection
GorlemZ 9cebf44
apis added (zodexpress)
GorlemZ 234b86b
ok persistence
GorlemZ 1f3e781
better testing with mock
GorlemZ 0b9b195
general update structure
GorlemZ b9efafe
error message attempt
GorlemZ 4a2e98e
fix on return error
GorlemZ cd3caee
logRes async update
GorlemZ e995b1b
error parsing discussion updates
GorlemZ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
version: "3.7" | ||
services: | ||
postgres: | ||
image: postgres:12.1-alpine | ||
environment: | ||
- POSTGRES_USER=root | ||
- POSTGRES_PASSWORD=root | ||
- POSTGRES_DB=root | ||
logging: | ||
options: | ||
max-size: 10m | ||
max-file: "3" | ||
ports: | ||
- "5438:5432" | ||
volumes: | ||
- local_test_andrea:/var/lib/postgresql/data | ||
- ./init.sql:/docker-entrypoint-initdb.d/init.sql | ||
|
||
volumes: | ||
local_test_andrea: |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
create table Results ( | ||
id SERIAL PRIMARY KEY, | ||
result varchar NOT NULL, | ||
log_game timestamp NOT NULL DEFAULT now() | ||
GorlemZ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import { z } from "zod"; | ||
import { date, z } from "zod"; | ||
GorlemZ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export enum Result { | ||
WIN = "You Win!!!", | ||
LOSE = "You lose :< ", | ||
DRAW = "It's a Draw!", | ||
} | ||
export const results = z.object({ | ||
GorlemZ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
log_game: z.ZodDate.create(), | ||
result: z.enum(["You Win!!!", "You lose :< ", "It's a Draw!"]), | ||
GorlemZ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
const ResultEnum = z.nativeEnum(Result); | ||
export type ResultEnum = z.infer<typeof ResultEnum>; | ||
export type Result = z.infer<typeof results>; |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pgPromise, { ParameterizedQuery as PQ } from "pg-promise"; | ||
import { Result } from "../model/result"; | ||
|
||
const cn = { | ||
host: "localhost", | ||
port: 5438, | ||
database: "root", | ||
user: "root", | ||
password: "root", | ||
max: 30, // use up to 30 connections | ||
}; | ||
|
||
const pgp = pgPromise(); | ||
const db = pgp(cn); | ||
|
||
export async function lastGame(): Promise<Result> { | ||
return await db.one<Result>( | ||
"SELECT log_game, result FROM results ORDER BY log_game DESC LIMIT 1" | ||
); | ||
} | ||
|
||
export async function logRes(res: String) { | ||
const addResult = new PQ("INSERT into results(result) VALUES($1)"); | ||
return await db.none(addResult, [res]); | ||
} | ||
|
||
export function closeDB() { | ||
db.$pool.end(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.