From 8380f79e0c6e8b27d15830ae53112a840e7641f1 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Wed, 6 Dec 2023 02:22:38 +0100 Subject: [PATCH] JavaScript/Prisma: Adjust settings for CrateDB --- .gitignore | 3 +- by-language/javascript-prisma/README.md | 131 +++--------------- .../javascript-prisma/prisma/schema.prisma | 4 +- 3 files changed, 24 insertions(+), 114 deletions(-) diff --git a/.gitignore b/.gitignore index 44639d77..8bf83c33 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ __pycache__ .coverage coverage.xml mlruns/ +node_modules/ archive/ -logs.log \ No newline at end of file +logs.log diff --git a/by-language/javascript-prisma/README.md b/by-language/javascript-prisma/README.md index a0435ca3..d8bf6ab3 100644 --- a/by-language/javascript-prisma/README.md +++ b/by-language/javascript-prisma/README.md @@ -1,131 +1,40 @@ -# Simple Node.js Script Example +# Using CrateDB with Prisma -This example shows how to use [Prisma Client](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client) in a **simple Node.js script** to read and write data in a SQLite database. You can find the database file with some dummy data at [`./prisma/dev.db`](./prisma/dev.db). -## Getting started +## About -### 1. Download example and install dependencies +[Prisma] is a next-generation Node.js and TypeScript ORM. -Download this example: -``` -npx try-prisma@latest --template javascript/script -``` - -Install npm dependencies: -``` -cd script -npm install -``` - -
Alternative: Clone the entire repo +## Details -Clone this repository: +This example shows how to use [Prisma Client] in a **simple Node.js script**, to +read and write data in a CrateDB database. -``` -git clone git@github.com:prisma/prisma-examples.git --depth=1 -``` - -Install npm dependencies: - -``` -cd prisma-examples/javascript/script -npm install +The folder has been scaffolded using this command: +```shell +npx try-prisma@latest --template javascript/script --install npm --name . --path . ``` -
-### 2. Create the database +## Usage -Run the following command to create your SQLite database file. This also creates the `User` and `Post` tables that are defined in [`prisma/schema.prisma`](./prisma/schema.prisma): +### Create the database -``` +Run the following command to submit the SQL DDL to the database. This will create +database tables for the `User` and `Post` entities that are defined in +[`prisma/schema.prisma`](./prisma/schema.prisma). +```shell npx prisma migrate dev --name init ``` -### 3. Run the script - -Execute the script with this command: - -``` +### Execute the script +```shell npm run dev ``` -## Switch to another database (e.g. PostgreSQL, MySQL, SQL Server, MongoDB) - -If you want to try this example with another database than SQLite, you can adjust the the database connection in [`prisma/schema.prisma`](./prisma/schema.prisma) by reconfiguring the `datasource` block. - -Learn more about the different connection configurations in the [docs](https://www.prisma.io/docs/reference/database-reference/connection-urls). - -
Expand for an overview of example configurations with different databases - -### PostgreSQL - -For PostgreSQL, the connection URL has the following structure: - -```prisma -datasource db { - provider = "postgresql" - url = "postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=SCHEMA" -} -``` - -Here is an example connection string with a local PostgreSQL database: - -```prisma -datasource db { - provider = "postgresql" - url = "postgresql://janedoe:mypassword@localhost:5432/notesapi?schema=public" -} -``` - -### MySQL - -For MySQL, the connection URL has the following structure: - -```prisma -datasource db { - provider = "mysql" - url = "mysql://USER:PASSWORD@HOST:PORT/DATABASE" -} -``` - -Here is an example connection string with a local MySQL database: - -```prisma -datasource db { - provider = "mysql" - url = "mysql://janedoe:mypassword@localhost:3306/notesapi" -} -``` - -### Microsoft SQL Server - -Here is an example connection string with a local Microsoft SQL Server database: - -```prisma -datasource db { - provider = "sqlserver" - url = "sqlserver://localhost:1433;initial catalog=sample;user=sa;password=mypassword;" -} -``` - -### MongoDB - -Here is an example connection string with a local MongoDB database: - -```prisma -datasource db { - provider = "mongodb" - url = "mongodb://USERNAME:PASSWORD@HOST/DATABASE?authSource=admin&retryWrites=true&w=majority" -} -``` - -
-## Next steps -- Check out the [Prisma docs](https://www.prisma.io/docs) -- Share your feedback in the [`#product-wishlist`](https://prisma.slack.com/messages/CKQTGR6T0/) channel on the [Prisma Slack](https://slack.prisma.io/) -- Create issues and ask questions on [GitHub](https://github.com/prisma/prisma/) -- Watch our biweekly "What's new in Prisma" livestreams on [Youtube](https://www.youtube.com/channel/UCptAHlN1gdwD89tFM3ENb6w) +[Prisma]: https://www.prisma.io/ +[Prisma Client]: https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client +[Simple Node.js Script Example]: https://github.com/prisma/prisma-examples/tree/latest/javascript/script diff --git a/by-language/javascript-prisma/prisma/schema.prisma b/by-language/javascript-prisma/prisma/schema.prisma index 1dee3021..c6977bc9 100644 --- a/by-language/javascript-prisma/prisma/schema.prisma +++ b/by-language/javascript-prisma/prisma/schema.prisma @@ -3,8 +3,8 @@ generator client { } datasource db { - provider = "sqlite" - url = "file:./dev.db" + provider = "postgresql" + url = "postgresql://crate@localhost:5432/mydb?schema=public" } model User {