Skip to content

Commit

Permalink
feat: remove postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
Akeboshiwind committed Aug 22, 2024
1 parent d370aef commit 9d69faf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 47 deletions.
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// This can be used to network with other containers or the host.
"forwardPorts": [5432,5433],
"forwardPorts": [/*5432,*/5433],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip install --user -r requirements.txt",
Expand All @@ -25,6 +25,7 @@
],
"settings": {
"sqltools.connections": [
/*
{
"previewLimit": 50,
"server": "localhost",
Expand All @@ -35,6 +36,7 @@
"username": "postgres",
"password": "postgres"
},
*/
{
"previewLimit": 50,
"server": "localhost",
Expand Down
20 changes: 10 additions & 10 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ services:
#network_mode: service:postgres
network_mode: host

postgres:
image: postgres:latest
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
network_mode: host
#postgres:
# image: postgres:latest
# restart: unless-stopped
# volumes:
# - postgres-data:/var/lib/postgresql/data
# environment:
# POSTGRES_USER: postgres
# POSTGRES_DB: postgres
# POSTGRES_PASSWORD: postgres
# network_mode: host

xtdb:
image: ghcr.io/xtdb/xtdb-standalone-ea:latest
Expand Down
26 changes: 8 additions & 18 deletions sql/setup_database.sql
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
-- @conn postgres

-- @block Create a table
CREATE TABLE employees (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
department VARCHAR(100),
salary INTEGER
);
-- @conn xtdb

-- 👇 Click here 👇
-- @block Insert sample data
INSERT INTO employees (name, department, salary) VALUES
('John Doe', 'IT', 75000),
('Jane Smith', 'HR', 65000),
('Bob Johnson', 'Finance', 80000),
('Alice Brown', 'Marketing', 70000),
('Charlie Davis', 'IT', 85000);

-- @block
DROP TABLE employees
INSERT INTO employees (_id, name, department, salary) VALUES
(1, 'John Doe', 'IT', 75000),
(2, 'Jane Smith', 'HR', 65000),
(3, 'Bob Johnson', 'Finance', 80000),
(4, 'Alice Brown', 'Marketing', 70000),
(5, 'Charlie Davis', 'IT', 85000);
30 changes: 12 additions & 18 deletions sql/workshop_exercises.sql
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
-- @conn postgres
-- @conn xtdb

-- @block
-- Exercise 1: Basic SELECT
-- Retrieve all employees from the IT department
SELECT * FROM employees WHERE department = 'IT';

-- @block
SELECT * FROM employees;

-- Exercise 2: Aggregation
-- Calculate the average salary for each department
-- @block
SELECT department, AVG(salary) as avg_salary
FROM employees
GROUP BY department;

-- @block
-- Exercise 3: Joins (assuming we add another table)
-- Create a departments table
CREATE TABLE departments (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
budget INTEGER
);

INSERT INTO departments (name, budget) VALUES
('IT', 500000),
('HR', 300000),
('Finance', 700000),
('Marketing', 400000);

-- @block
INSERT INTO departments (_id, name, budget) VALUES
(1, 'IT', 500000),
(2, 'HR', 300000),
(3, 'Finance', 700000),
(4, 'Marketing', 400000);

-- Join employees with departments to get department budgets
-- @block
SELECT e.name, e.department, d.budget
FROM employees e
JOIN departments d ON e.department = d.name;

-- @block
-- Exercise 4: Subqueries
-- Find employees who earn more than the average salary
-- @block
SELECT name, salary
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);

0 comments on commit 9d69faf

Please sign in to comment.