-
Notifications
You must be signed in to change notification settings - Fork 170
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
Add a tutorial on setting up Drizzle with Neon #289
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ananis25! Thank you for your efforts, we appreciate it! There are some edits that need to be implemented before merging this PR.
All tutorials with databases should be consistent and have similar structure/tables/queries. For instance you can follow tutorials for Turso & Supabase.
}); | ||
``` | ||
|
||
The code defines two tables: `authors`, which will contain the list of all the authors, and `books`, which will contain the list of books written by the authors. Each book is associated with an author using the `authorId` field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this info so it would be like in other tutorials
tsx ./src/migrate.ts | ||
``` | ||
|
||
Learn more about the [migration process](https://orm.drizzle.team/docs/migrations). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add information about drizzle-kit push
command. You can find the example in other tutorials
import { db } from './db'; | ||
import { authors, books } from './schema'; | ||
|
||
export async function getBooksByAuthor(authorId: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great to set returning type to show the type of query result
} | ||
``` | ||
|
||
#### Select data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also add more examples like in other tutorials
|
||
### Basic file structure | ||
|
||
This is the basic file structure of the project. In the `src/db` directory, we have database-related files including connection in `db.ts`, schema definitions in `schema.ts`, and a migration script in `migrate.ts` file which is responsible for applying migrations that stored in the `migrations` directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove part about migrate.ts
cause we use drizzle-kit migrate
command for applying migrations
- You should have installed the `dotenv` package for managing environment variables, and `tsx` to run typescript files. | ||
<Npm> | ||
dotenv | ||
tsx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is used only for applying migrations then you can remove it as we use drizzle-kit migrate
command
Hey @realmikesolo - thanks for looking into the PR! Before, I make the change from We wanted Neon users to use the serverless driver for all their operations, hence the separate migration script. |
Hey @ananis25! As for now you can't explicity set UPD: I have asked core team member and we will think how to do it |
Small update: It is not necessary for users to know how the Drizzle kit connects to the database. The Drizzle kit looks for installed drivers ( If |
@realmikesolo - thank you for clarifying. I've made some edits, let me know if it looks okay. |
Hello @ananis25. I have used this tutorial and everything worked out. Great job! We are ready to merge, but there is one thing. Could you remove |
Sure, removed it. I was using it to test the code locally. |
This PR adds a tutorial on using Drizzle with Neon Postgres database. There is an existing tutorial on a nextjs project with drizzle + Neon, but this one details the basic setup steps (migration/queries).
(I write technical content for Neon)