Giter VIP home page Giter VIP logo

hello-htmx's Introduction

Hello HTMX!

To run

Docker compose -up

Should be running on port 80

Table Setup if lost

Here is the initial setup done directly via SQL.

NB the pwd is unhashed so is insecure

CREATE users:

CREATE TABLE users (
	id INT(11) NOT NUll AUTO_INCREMENT,
    username VARCHAR(30) NOT NULL,
	pwd VARCHAR(255) NOT NULL,
    email VARCHAR(100) NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id)
); 

CREATE comments. The ON DELETE SET NULL ensures that if a user deletes their account, the users_id will be set to NULL (and therefore will allow a user to delte thier account and make sure that all their comments remain, for example.)

CREATE TABLE comments (
  	id INT(11) NOT NULL AUTO_INCREMENT,
    username VARCHAR(30) NOT NULL,
    comment_text TEXT NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    users_id INT(11),
    PRIMARY KEY (id),
    FOREIGN KEY (users_id) REFERENCES users (id) ON DELETE SET NULL
);

INSERT INTO users. Note the unsafe use of pwd as per above:

INSERT INTO users (username, pwd, email) VALUES ('HopOnPop', 'password456', '[email protected]');

UPDATE users:

UPDATE users SET username = 'newUSername', pwd = 'moresecure' WHERE id = 2;

DELETE users:

**Warning, of course ***

DELETE FROM users WHERE id = 1

INSERT INTO comments:

INSERT INTO comments (username, comment_text, users_id ) VALUES (
    'furiousB', 'Hello World!', 1
);

Basic INNER JOIN to grab user and comments

    SELECT * FROM users INNER JOIN comments ON users.id = comments.users_id;

Specific INNER JOIN:

    SELECT users.username, comments.comment_text, comments.created_at  FROM users INNER JOIN comments ON users.id = comments.users_id;

LEFT JOIN / RIGHT JOIN

Returns all users, whether or not they have comments:

SELECT * FROM users LEFT JOIN comments ON users.id = comments.users_id;

Returns all comments (but not all the users if they hane't made a comment):

SELECT * FROM users RIGHT JOIN comments ON users.id = comments.users_id;

hello-htmx's People

Contributors

brendantuckerman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.