This project was created using bun init
in bun v1.0.18. Bun is a fast all-in-one JavaScript runtime.
bun install
bun run index.ts
- generate schema
npm run generate
- run migration
cd db/schema
bun run index.ts
To access PostgreSQL in Debian and create a new database, you can follow these steps:
Make sure PostgreSQL is installed on your Debian system. You can do this by running:
sudo apt update
sudo apt install postgresql postgresql-contrib
This will install PostgreSQL and some additional utilities.
The installation process should automatically start the PostgreSQL service. If not, you can start it manually:
sudo service postgresql start
You can access the PostgreSQL shell using the psql
command. By default, the PostgreSQL superuser is named postgres
. Use the following command to access the PostgreSQL shell as the postgres
user:
sudo -u postgres psql
This will open a PostgreSQL shell prompt.
Now, within the PostgreSQL shell, you can create a new database. Replace your_database
with the desired name for your database:
CREATE DATABASE your_database;
You might want to create a new user and grant them privileges on the newly created database. Replace your_user
and your_password
with the desired username and password:
CREATE USER your_user WITH PASSWORD 'your_password';
ALTER ROLE your_user SET client_encoding TO 'utf8';
ALTER ROLE your_user SET default_transaction_isolation TO 'read committed';
ALTER ROLE your_user SET timezone TO 'UTC';
Grant the necessary privileges to the user on the database:
GRANT ALL PRIVILEGES ON DATABASE your_database TO your_user;
Exit the PostgreSQL shell by typing:
\q
You can now test the connection to the new database using the psql
command:
psql -U your_user -d your_database -h localhost
To access PostgreSQL running in a Docker container, you can use the docker exec
command to execute a command inside the container. Here are the steps:
Assuming you already have a PostgreSQL Docker container running, if not, you can run it with a command similar to the following:
docker run --name postgres-container -e POSTGRES_PASSWORD=your_password -p 5432:5432 -d postgres
Replace your_password
with the desired password.
Use the following command to access the PostgreSQL shell inside the running container:
docker exec -it postgres-container psql -U postgres
This assumes that the default PostgreSQL superuser is named postgres
. If you are using a different superuser, replace postgres
with the appropriate username.
Inside the PostgreSQL shell, you can create a new database. Replace your_database
with the desired name for your database:
CREATE DATABASE your_database;
Create a new user and grant them privileges on the newly created database. Replace your_user
and your_password
with the desired username and password:
CREATE USER your_user WITH PASSWORD 'your_password';
ALTER ROLE your_user SET client_encoding TO 'utf8';
ALTER ROLE your_user SET default_transaction_isolation TO 'read committed';
ALTER ROLE your_user SET timezone TO 'UTC';
Grant the necessary privileges to the user on the database:
GRANT ALL PRIVILEGES ON DATABASE your_database TO your_user;
Exit the PostgreSQL shell by typing:
\q
You can test the connection to the new database from your host machine using the psql
command:
psql -h localhost -U your_user -d your_database -W
To browse a PostgreSQL database, you can use the psql
command-line tool or a graphical user interface (GUI) tool like pgAdmin. Below are some common PostgreSQL commands that you can use in the psql
command-line interface to interact with and browse the database:
-
Connect to a Database:
psql -U username -d database_name -h host -p port
Replace
username
,database_name
,host
, andport
with your actual PostgreSQL username, database name, host, and port. -
List Databases:
\l
-
Connect to a Different Database:
\c database_name
-
List Tables:
\dt
-
Show Table Structure:
\d table_name
-
Display Table Data:
SELECT * FROM table_name;
-
Describe Table Columns:
\d+ table_name
-
Execute SQL Query:
SELECT column1, column2 FROM table_name WHERE condition;
-
Exit
psql
:\q
-
Help:
\?