dwyl / learn-postgresql

🐘 Learn how to use PostgreSQL and Structured Query Language (SQL) to store and query your relational data. 🔍
212 stars 23 forks source link

PostgreSQL Graphical User Interface (GUI) #43

Open nelsonic opened 6 years ago

nelsonic commented 6 years ago

Today I learned about "DBeaver". (thanks to @Danwhy!) it's an Open Source Database GUI that supports PostgreSQL and has several nice features! see: https://github.com/dbeaver/dbeaver and https://dbeaver.jkiss.org/docs/features

I particularly like the Schema (Table Relationships) Viewer: image Which allowed us to visualise the schema of our DB and show it to the rest of the team without having to manually "draw" it ourselves!

Download the "free" (Community) version: https://dbeaver.jkiss.org/download

It was "hidden" on this list: https://wiki.postgresql.org/wiki/Community_Guide_to_PostgreSQL_GUI_Tools but we never noticed it before, so thanks Dan for demo-ing it to us! ❤️

nelsonic commented 6 years ago

DBeaver is compatible with a lot of Database engines! 😮 image

Had to download the JDBC PostgreSQL driver to use it: image

nelsonic commented 5 years ago

https://dbeaver.io image

Visit: https://dbeaver.io/download and pick the Community Edition installer for your Operating System: image

image

Intro: image

License: Apache License Version 2.0 image

Agree: image

Space: image

Installing: image

Success: image

Move installer to trash: (you can always restore/retrieve it from the trash if needed) image

Open the App: image

Loading screen:

image

Select your database connection:

image

Same screen but constrained to highlight the modal:

image

Select PostgreSQL and click "Next >" image

Test the connection: image

Download PostgreSQL driver files: image

Connection Success: image

Change name of Database to "test": image

Re-test the connection: image

No Tables: image

My first impression of the UI is that it's overwhelming. 🙄 I think if I was totally new to software development, this screen with all the tiny icons and very little in the way of labels would be intimidating. Like "What Now?", "What do I do Next...?" Good thing I'm on a mission and (comparatively) small obstacles aren't going to deter me from achieving my goal! 🎯 I know what to do when nobody tells me what to to; explore the interface!

In the top left (5th from the left), there's an icon (which I discovered by hovering my mouse cursor over all the icons and reading the tool-tips) that opens an SQL Editor: image

Create Table: copy-paste the create script from schema.sql, click the ▶️ button to run the script: image

Looks like it succeeded: image

Confirm that the table was created, you may need to refresh the schema: image

Attempt to insert a person into the people table: image

Confirm that the test person was inserted into the people table by viewing the data in the table: image

No idea why the inserted_at field is being displayed as a number ... Oh, that's right, because I defined it that way (above)! Derp! Let's fix it.

Drop it ... https://youtu.be/RaCodgL9cvk Note: you will need to disconnect from test and instead connect to postgres to perform this query:

DROP DATABASE test;

image

CREATE DATABASE test;

image

How does Phoenix do it...? Open up a Phoenix app https://github.com/dwyl/phoenix-chat-example and check inserted_at: image Looked up how to define it: https://stackoverflow.com/questions/28506589/default-datetime-elixir

Repeat the previous CREATE TABLE query:

CREATE TABLE IF NOT EXISTS people (
  id SERIAL PRIMARY KEY,
  inserted_at TIMESTAMP DEFAULT EXTRACT(EPOCH FROM CURRENT_TIMESTAMP),
  name VARCHAR(100) DEFAULT NULL,
  username VARCHAR(50) DEFAULT NULL
);

image

Re-insert the dummy data:

INSERT INTO people (name, username)
  SELECT name, username FROM people
  UNION
  VALUES (
    'Jimmy Testuser',
    'jimmy'
  )
  EXCEPT
  SELECT name, username FROM people;

That's better, inserted_at is timestamp. ✅ image

Ok. that's DBeaver setup & working ... now back to #51