Write a program that connects to a Postgres database and stores contact information in a table.
Sample input:
$ go run .
First name: John
Last name: Smith
Phone no: +1555123456
Email: [email protected]
Date of birth: 1998-05-01
SAVED!Remember to use correct data types. Refer to Postgres documentation for CREATE TABLE, INSERT INTO.
Write a program that prompts the user for the relevant data using fmt.Scanf or fmt.Scanln.
Convert the date of birth to a Go data structure using time.Parse.
Write a program that connects to a PostgreSQL database using database/sql or sqlx.
Use URL format for the connection string:
https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
Execute a simple SQL query (e. g. select 2 + 2 or select now()) and print its output to STDOUT to ensure that the connection works.
Write a function that creates a table if it does not exist. This table must have a primary key (a bigint incrementing automatically).
You can use create table if not exists ....
For ID, use ... generated by default by identity.
Write the data to the database table using database/sql or sqlx.
Consult the docs for insert into ....