Initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export DATABASE_URL=postgres://postgres:rustiscool@localhost/postgres
|
||||
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "demo"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
sqlx = { version = "0.8.6", features = ["macros", "postgres", "runtime-tokio"] }
|
||||
tokio = { version = "1.51.1", features = ["full"] }
|
||||
@@ -0,0 +1,15 @@
|
||||
services:
|
||||
database:
|
||||
image: postgres:18
|
||||
ports:
|
||||
- 5432:5432
|
||||
environment:
|
||||
- TZ=Europe/Amsterdam
|
||||
- PGTZ=Europe/Amsterdam
|
||||
- POSTGRES_PASSWORD=rustiscool
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres -d postgres"]
|
||||
interval: 10s
|
||||
retries: 5
|
||||
start_period: 10s
|
||||
timeout: 10s
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO users (first_name, last_name) VALUES ('Tim', 'Huizinga');
|
||||
INSERT INTO users (first_name, last_name) VALUES ('Sebastiano', 'Tronto');
|
||||
@@ -0,0 +1 @@
|
||||
SELECT (first_name) FROM users;
|
||||
@@ -0,0 +1,23 @@
|
||||
use sqlx::{Connection, PgConnection};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let url = std::env::var("DATABASE_URL").unwrap();
|
||||
let mut conn = PgConnection::connect(&url).await.unwrap();
|
||||
|
||||
// sqlx::migrate!("migrations").run(&conn).await?;
|
||||
|
||||
let users = sqlx::query!("SELECT * FROM users")
|
||||
.fetch_all(&mut conn)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// let users = sqlx::query_file!("src/get_users.sql")
|
||||
// .fetch_all(&mut conn)
|
||||
// .await
|
||||
// .unwrap();
|
||||
|
||||
println!("{users:#?}");
|
||||
|
||||
// users[0].first_name;
|
||||
}
|
||||
Reference in New Issue
Block a user