Skip to content

Homework 07#8

Open
aendrevv wants to merge 12 commits into
mainfrom
homework-07
Open

Homework 07#8
aendrevv wants to merge 12 commits into
mainfrom
homework-07

Conversation

@aendrevv

Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/app.js
Comment on lines +10 to +11
db.setType('knex');
console.log(`New DB type is ${db.getType()}`);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Оце можна не робити. Під час зустрічі я це робив лише для зразку. Це можна зробити через envvar DB_WRAPPER.

Comment thread src/app.js
Comment on lines +46 to +47
process.on('SIGUSR1', exitHandler);
process.on('SIGUSR2', exitHandler);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Оці сигнали краще не закривати мабуть все-таки.

Comment thread src/config/index.js
Comment on lines +52 to +54
products: process.env.TABLE_NAME || 'products',
colors: 'colors',
types: 'types',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Якщо одну назву виніс, то чому інші ні? 🙂

Comment thread src/db/knex/index.js
createTables: async () => {
try {
await knex.raw(
`SELECT 'CREATE DATABASE ${database}' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '${database}')`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Боюсь, що якщо бази нема, то воно і підконектитись не зможе. Загалом створення бази і таблиць краще не робити з коду. Для цього і є міграції.
Ну і тут екранування нема.

Comment thread src/db/knex/index.js
throw err;
}

const [product] = await knex(tables.products)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут можна зробити одним комплексним запитом в базу, щоб спочатку не вигрібати ці айдішки окремо.

Comment thread src/db/pg/index.js
const { Pool } = require('pg');

const name = 'pg';
const table = 'products';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для чого це?

Comment thread src/db/pg/index.js
Comment on lines +12 to +22
await client.query(
`CREATE TABLE IF NOT EXISTS ${tablename}(
id INT GENERATED ALWAYS AS IDENTITY,
type VARCHAR(255),
color VARCHAR(255),
price NUMERIC(10,2),
quantity BIGINT NOT NULL,
created_at TIMESTAMP DEFAULT NULL,
updated_at TIMESTAMP DEFAULT NULL,
deleted_at TIMESTAMP DEFAULT NULL,
PRIMARY KEY (type, color, price)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Стара неактуальна таблиця? Взагалі ці createTable для кожного враппера краще прибрати.

Comment thread src/db/pg/index.js
const timestamp = new Date();

const res = await client.query(
`INSERT INTO ${table} (type, color, price, quantity, created_at, updated_at, deleted_at) VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT (type, color, price) DO UPDATE SET quantity = ${table}.quantity + $4 RETURNING *`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не актуально для домашки №7?

Comment thread src/server/controller.js
}
};

const testc = async (req, res) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Погана назва, так незрозуміло краще не називати.

type: e.type || 'no type',
color: e.color || 'no color',
quantity: e.quantity || 0,
price: +e.price + 0.99,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Що це за 0.99 щоразу? 🙂 Просто прикол?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants