-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JavaScript/Prisma: Adjust settings for CrateDB
- Loading branch information
Showing
3 changed files
with
24 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ __pycache__ | |
.coverage | ||
coverage.xml | ||
mlruns/ | ||
node_modules/ | ||
archive/ | ||
logs.log | ||
logs.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` | ||
|
||
<details><summary><strong>Alternative:</strong> Clone the entire repo</summary> | ||
## 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 . | ||
``` | ||
|
||
</details> | ||
|
||
### 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). | ||
|
||
<details><summary>Expand for an overview of example configurations with different databases</summary> | ||
|
||
### 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" | ||
} | ||
``` | ||
|
||
</details> | ||
|
||
## 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters