Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kysely #32

Merged
merged 18 commits into from
Feb 8, 2025
Merged

Kysely #32

merged 18 commits into from
Feb 8, 2025

Conversation

matejchalk
Copy link
Contributor

@matejchalk matejchalk commented Jan 11, 2025

Closes #21

Features

  • Set up local database using postgres Docker image.
    • Also integrated Adminer for UI access to database (also via Docker).
  • Set up Kysely for using database in TypeScript.
    • Types are generated from local database using Kanel, with some customizations like de-pluralizing type names and adding suffix (e.g. public.users Postgres table transformed to UserModel type).
    • Set up migrations with initial creation of users table.
    • Implemented database client for users table.
    • Set up seeds which insert test user ([email protected]) in non-production environment.
  • Created new db library for client and models.
    • Customized defaults for Nx generator.
  • Integrated @th/db in api to resolve "current" user.
    • Using mappers to use database models in resolvers.

Testing

Running npm start will spin up local database (requires Docker Compose) and run migration.

Visit http://localhost:8080/?pgsql=db&username=admin&db=th_db&ns=public in browser and sign in with password admin:

image

View test user [email protected] in users table:

image

(Optional) Add new user

Go to users table and add new item. You can use SHA256 - Online Tools to hash your password, or just generate a random hash with node -e "console.log(require('crypto').randomBytes(32).toString('hex'))".

image

See user logged by website and cms (as in #27 description), or query GraphQL API directly:

image

If you need to drop local database, run docker compose down (loses data!).

Next steps

This database setup with npm-run-all works, but isn't very compatible Nx cache. I would like to convert these package.json scripts (starting DB container, migration, seeding) into Nx targets for the db library, so that the dependencies are part of the Nx task graph.

@matejchalk matejchalk self-assigned this Jan 11, 2025
@matejchalk matejchalk added 🧹 maintenance project maintenance 🚀 setup project setup 🛠️ tooling tooling integration and maintenance labels Jan 11, 2025
@matejchalk matejchalk marked this pull request as ready for review January 12, 2025 10:12
@matejchalk matejchalk added the 🦾 CI/CD continuous integration and deployment label Jan 12, 2025
@matejchalk matejchalk requested a review from Tlacenka January 12, 2025 10:12
Tlacenka
Tlacenka previously approved these changes Feb 8, 2025
Copy link
Contributor

@Tlacenka Tlacenka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, thank you for the extensive documentation and guide on how to run it. 👍

@matejchalk matejchalk merged commit 30e0a03 into main Feb 8, 2025
6 checks passed
@matejchalk matejchalk deleted the kysely branch February 8, 2025 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🦾 CI/CD continuous integration and deployment 🧹 maintenance project maintenance 🚀 setup project setup 🛠️ tooling tooling integration and maintenance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kysely setup with codegen
2 participants