Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
jharrell authored Mar 27, 2024
2 parents a95037a + ab1465e commit 5d30b25
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 224 deletions.
1 change: 1 addition & 0 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ const siteConfig = {
footer: {
newsletter: {
text: 'Stay up to date with the latest features and changes to Prisma',
GATSBY_BREVO_API_KEY: process.env.GATSBY_BREVO_API_KEY || '',
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion content/200-orm/050-overview/500-databases/400-mysql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ The MySQL connector maps the [scalar types](/orm/prisma-schema/data-model/models
| `Float` | `DOUBLE` | |
| `Decimal` | `DECIMAL(65,30)` | |
| `DateTime` | `DATETIME(3)` | |
| `Json` | `LONGTEXT | See https://mariadb.com/kb/en/json-data-type/ |
| `Json` | `LONGTEXT` | See https://mariadb.com/kb/en/json-data-type/ |
| `Bytes` | `LONGBLOB` | |

### Native type mappings
Expand Down
7 changes: 4 additions & 3 deletions content/200-orm/050-overview/500-databases/880-supabase.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ If you'd like to use the [connection pooling feature](https://supabase.com/docs/

```env file=.env
# Connect to Supabase via connection pooling with Supavisor.
DATABASE_URL="postgres://postgres.[your-supabase-project]:[password]@aws-0-eu-central-1.pooler.supabase.com:6543/postgres?pgbouncer=true"
DATABASE_URL="postgres://postgres.[your-supabase-project]:[password]@aws-0-[aws-region].pooler.supabase.com:6543/postgres?pgbouncer=true"
```

If you would like to use the Prisma CLI in order to perform other actions on your database (e.g. migrations) you will need to add a `DIRECT_URL` environment variable to use in the `datasource.directUrl` property so that the CLI can bypass Supavisor:

```env file=.env highlight=4-5;add
# Connect to Supabase via connection pooling with Supavisor.
DATABASE_URL="postgres://postgres.[your-supabase-project]:[password]@aws-0-eu-central-1.pooler.supabase.com:6543/postgres?pgbouncer=true"
DATABASE_URL="postgres://postgres.[your-supabase-project]:[password]@aws-0-[aws-region].pooler.supabase.com:6543/postgres?pgbouncer=true"
# Direct connection to the database. Used for migrations.
DIRECT_URL="postgres://postgres:[password]@db.[your-supabase-project].supabase.co:5432/postgres"
DIRECT_URL="postgres://postgres.[your-supabase-project]:[password]@aws-0-[aws-region].pooler.supabase.com:5432/postgres"
```

You can then update your `schema.prisma` to use the new direct URL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ preview: true

Prisma Client supports full-text search for **PostgreSQL** databases in versions 2.30.0 and later, and **MySQL** databases in versions 3.8.0 and later. With full-text search enabled, you can add search functionality to your application by searching for text within a database column.

> **Note**: There currently is a [known issue](https://github.com/prisma/prisma/issues/23627) in the full-text search feature. If you observe slow search queries, you can [optimize your query with raw SQL](#full-text-search-with-raw-sql).
</TopBlock>

## Enabling full-text search
Expand Down Expand Up @@ -243,3 +245,37 @@ const result = await prisma.blogs.findMany({
```
However, if you try to search on `title` alone, the search will fail with the error "Cannot find a fulltext index to use for the search" and the message code is `P2030`, because the index requires a search on both fields.
## Full-text search with raw SQL
Full-text search is currently in Preview and due to a [known issue](https://github.com/prisma/prisma/issues/23627), you may be seeing slow search queries. If that's the case, you can optimize your query using [raw SQL](/orm/prisma-client/queries/raw-database-access).
### PostgreSQL
In PostgreSQL, you can use `to_tsvector` and `to_tsquery` to express your search query:
```ts
const term = `cat`
const result =
await prisma.$queryRaw`SELECT * FROM "Blog" WHERE to_tsvector('english', "Blog"."content") @@ to_tsquery('english', ${term});`
```
> **Note**: Depending on your language preferences, you may exchange `english` against another language in the SQL statement.
If you want to include a wildcard in your search term, you can do this as follows:
```ts
const term = `cat:*`
const result =
await prisma.$queryRaw`SELECT * FROM "Blog" WHERE to_tsvector('english', "Blog"."content") @@ to_tsquery('english', ${term});`
```
### MySQL
In MySQL, you can express your search query as follows:
```ts
const term = `cat`
const result =
await prisma.$queryRaw`SELECT * FROM Blog WHERE MATCH(content) AGAINST(${term} IN NATURAL LANGUAGE MODE);`
```
Loading

0 comments on commit 5d30b25

Please sign in to comment.