Back to Prisma1

Overview

docs/1.19/prisma-graphql-api/reference/raw-database-access-qwe4.mdx

1.34.122.3 KB
Original Source

import Code from 'components/Markdown/Code'

export const meta = { title: "Raw Database Access", position: 70, }

Overview

You can access the native API of the underlying database and perform complex operations.

Datamodel for examples on this page

All example subscriptions on this page are based on a Prisma service configured with this datamodel:

graphql
type User {
  id: ID! @unique
  name: String!
  createdAt: DateTime!
  updatedAt: DateTime!
}

Docker configuration

To enable raw database access, add rawAccess to your docker-compose.yml file.

<Code languages={["MySQL", "PostgreSQL"]}>

yml
version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.19
    restart: always
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        databases:
          default:
            connector: mysql
            host: mysql
            port: 3306
            user: root
            password: prisma
            migrations: true
  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: prisma
    volumes:
      - mysql:/var/lib/mysql
volumes:
  mysql: ~
yml
version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.19
    restart: always
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        databases:
          default:
            connector: postgres
            host: postgres
            port: 5432
            # port: 3306
            user: prisma
            password: prisma
            migrations: true
            rawAccess: true
  postgres:
    image: postgres:10.5
    restart: always
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: prisma
      POSTGRES_PASSWORD: prisma
    volumes:
      - postgres:/var/lib/postgresql/data
volumes:
  postgres: ~
</Code>

Examples

To create a new User through the native API, you can use the executeRaw mutation.

graphql
mutation {
  executeRaw(query: "INSERT INTO default$default.\"User\" (Id, Name, \"updatedAt\",\"createdAt\") VALUES ('cjnkpvm0b000d0b22j7csr04v', 'Abhi', '2018-10-22T19:54:47.606Z', '2018-10-22T19:54:47.606Z');")
}

To find all Users

graphql
mutation {
  executeRaw(query: "SELECT * FROM default$default.\"User\"")
}