This project combines Fastify with Kysely for building a web application with a PostgreSQL database backend.
Before starting the project, ensure you have the following installed on your machine:
- Node.js
- PostgreSQL
git clone <https://github.com/yogyy/fastky.git>
cd fasky
npm install
Execute the following SQL commands to create the necessary table in your PostgreSQL database:
CREATE TABLE ky_user (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
username VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(255) NOT NULL,
role "UserType" NOT NULL DEFAULT 'user'::"UserType",
is_active BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE ky_user ADD COLUMN uuid UUID DEFAULT gen_random_uuid();
CREATE OR REPLACE FUNCTION trigger_set_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER set_updated_at
BEFORE UPDATE ON ky_user
FOR EACH ROW
EXECUTE PROCEDURE trigger_set_updated_at();
Copy the sample .env file and update it with your database connection details:
cp .env.sample .env
Run the following command to generate TypeScript types for your database:
npm run db:type
Execute the following command to run the tests:
npm run test
Now you're ready to start developing your Fastify + Kysely project!