chore: remove diesel example

This commit is contained in:
Dmitriy Pleshevskiy 2022-07-21 20:47:25 +03:00
parent e22329cb2c
commit 40c81801c7
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
12 changed files with 0 additions and 152 deletions

View file

@ -1 +0,0 @@
DATABASE_URL=postgres://user:test@localhost:5534/db

View file

@ -1,13 +0,0 @@
[package]
name = "itconfig-diesel-example"
version = "0.1.0"
authors = ["Dmitriy Pleshevskiy <dmitriy@ideascup.me>"]
edition = "2018"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
itconfig = { path = "../../itconfig", default-features = false, features = ["macro"] }
dotenv = "0.15.0"
diesel = { version = "1.4.6", features = ["postgres"] }

View file

@ -1,5 +0,0 @@
# For documentation on how to configure this file,
# see diesel.rs/guides/configuring-diesel-cli
[print_schema]
file = "schema.rs"

View file

@ -1,11 +0,0 @@
version: '3'
services:
postgresql:
image: postgres:12-alpine
ports:
- 5534:5432
environment:
POSTGRES_PASSWORD: test
POSTGRES_USER: user
POSTGRES_DB: db

View file

@ -1,51 +0,0 @@
#[macro_use]
extern crate diesel;
mod schema;
use diesel::prelude::*;
use dotenv::dotenv;
itconfig::config! {
DATABASE_URL,
}
fn main() {
dotenv().expect("dotenv setup to be successful");
config::init();
let connection = establish_connection();
let posts = get_posts(&connection);
println!("Displaying {} posts", posts.len());
for post in posts {
println!();
println!("{}", post.title);
println!("----------");
println!("{}", post.body);
}
}
fn get_posts(connection: &PgConnection) -> Vec<Post> {
use crate::schema::posts::dsl::*;
posts
.filter(published.eq(true))
.limit(5)
.get_results::<Post>(connection)
.expect("Error loading posts")
}
fn establish_connection() -> PgConnection {
let database_url = config::DATABASE_URL();
PgConnection::establish(database_url)
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
}
#[derive(Queryable)]
struct Post {
pub id: i32,
pub title: String,
pub body: String,
pub published: bool,
}

View file

@ -1,6 +0,0 @@
-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping. This file is safe to edit, any future
-- changes will be added to existing projects as new migrations.
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
DROP FUNCTION IF EXISTS diesel_set_updated_at();

View file

@ -1,36 +0,0 @@
-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping. This file is safe to edit, any future
-- changes will be added to existing projects as new migrations.
-- Sets up a trigger for the given table to automatically set a column called
-- `updated_at` whenever the row is modified (unless `updated_at` was included
-- in the modified columns)
--
-- # Example
--
-- ```sql
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
--
-- SELECT diesel_manage_updated_at('users');
-- ```
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
BEGIN
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
BEGIN
IF (
NEW IS DISTINCT FROM OLD AND
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
) THEN
NEW.updated_at := current_timestamp;
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

View file

@ -1,2 +0,0 @@
-- This file should undo anything in `up.sql`
DROP TABLE posts;

View file

@ -1,12 +0,0 @@
-- Your SQL goes here
CREATE TABLE posts (
id SERIAL PRIMARY KEY,
title VARCHAR NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL DEFAULT 'f'
);
INSERT INTO posts (title, body, published)
VALUES ('First post', 'Interesting body', 't'),
('Second post', 'Very interesting post', 't'),
('Draft post', 'This is post will not be shown', 'f');

View file

@ -1,8 +0,0 @@
table! {
posts (id) {
id -> Int4,
title -> Varchar,
body -> Text,
published -> Bool,
}
}

View file

@ -61,8 +61,6 @@ tokio = { version = "1.2.0", features = ["macros", "rt-multi-thread"] }
bytes = "1.0.1"
futures-util = { version = "0.3.13", default-features = false }
pretty_env_logger = "0.4.0"
dotenv = "0.15.0"
diesel = { version = "1.4.8", features = ["postgres"] }
[badges]
maintenance = { status = "passively-maintained" }
@ -71,11 +69,6 @@ maintenance = { status = "passively-maintained" }
[package.metadata.docs.rs]
all-features = true
[[example]]
name = "diesel"
path = "../examples/diesel/main.rs"
required-features = ["macro"]
[[example]]
name = "hyper"
path = "../examples/hyper.rs"