stumbled upon <https://github.com/prisma/prisma/is...
# orm-help
c
stumbled upon https://github.com/prisma/prisma/issues/2052 which seems to provide a few usage examples, unfortunately i haven't been able to get the most basic of them to work though
d
Prisma client does not have
$raw
support yet. We hope to add it soon 🙂
f
@cedric Hi! Please use threads 🙂 I think you can try the executeRaw with
prisma-binding
. About aggregation functions, only
count
is implemented but support for more of them is planned: https://github.com/prisma/prisma/issues/1312
🙌 1
c
thanks for the reply @divyendu. i tried with prisma binding and unfortunately it seems to produce the same issue as playground
Copy code
const { Prisma } = require('prisma-binding')

const prisma = new Prisma({
  typeDefs: './prisma.graphql',
  endpoint: '<https://localhost:4447>'
})

// A `main` function so that we can use async/await
async function main() {
  // Read all users from the database and print them to the console
  const result = await prisma.request(`mutation {
    executeRaw(query: "SELECT 1") {
      rows
    }
  }`)
  console.log(result)
}

main().catch(e => console.error(e))
Copy code
node client/index.js
{ errors:
   [ { GraphQLError: Cannot query field "executeRaw" on type "Mutation".
         at Object.Field (/Users/cedric/src/spantree/spantree-os-primsa-sandbox/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:65:31)
         at Object.enter (/Users/cedric/src/spantree/spantree-os-primsa-sandbox/node_modules/graphql/language/visitor.js:324:29)
         at Object.enter (/Users/cedric/src/spantree/spantree-os-primsa-sandbox/node_modules/graphql/language/visitor.js:366:25)
         at visit (/Users/cedric/src/spantree/spantree-os-primsa-sandbox/node_modules/graphql/language/visitor.js:254:26)
         at visitUsingRules (/Users/cedric/src/spantree/spantree-os-primsa-sandbox/node_modules/graphql/validation/validate.js:74:22)
         at validate (/Users/cedric/src/spantree/spantree-os-primsa-sandbox/node_modules/graphql/validation/validate.js:59:10)
         at graphqlImpl (/Users/cedric/src/spantree/spantree-os-primsa-sandbox/node_modules/graphql/graphql.js:106:50)
         at /Users/cedric/src/spantree/spantree-os-primsa-sandbox/node_modules/graphql/graphql.js:66:223
         at new Promise (<anonymous>)
         at Object.graphql (/Users/cedric/src/spantree/spantree-os-primsa-sandbox/node_modules/graphql/graphql.js:63:10)
       message: 'Cannot query field "executeRaw" on type "Mutation".',
       locations: [Array],
       path: undefined } ] }
d
What is your Prisma server version?
c
1.18.1
here's my docker-compose config
Copy code
version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.18
    restart: always
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        databases:
          default:
            connector: mysql
            host: db
            port: 3306
            user: root
            password: prisma
            migrations: true
            rawAcess: true
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: prisma
    volumes:
      - mysql:/var/lib/mysql
  # postgres:
  #   image: postgres:10.5
  #   restart: always
  #   environment:
  #     POSTGRES_USER: prisma
  #     POSTGRES_PASSWORD: prisma
  #   volumes:
  #     - postgres:/var/lib/postgresql/data
volumes:
  # postgres:
  mysql:
(i've tried both postgres and mysql)
ah! in typing that a discovered an typo in my config...
rawAcess
instead of
rawAccess
now i'm hitting this
but that appears to be a known issue with mysql: https://github.com/prisma/prisma/issues/3300
d
Please use <schema>.Users in the query schama => service name + "." + stage name
c
ah
d
Did that work?
Please create usability issues for this 🙏 We can make this workflow better 🙂
c
sorry had a meeting
one sec, i'm going to connect to the database to determine the schema it's using
there appears to be something wrong with my environment as i was switching back and forth between postgres and mysql
even after doing a prisma deploy, there don't appear to be any tables in the database anymore 🙂
investigating
hmm, i'm wondering if prisma isn't actually connecting up to my postgres database. i'm not seeing any tables in there
d
you can delete everything from docker and start over 🙂
c
yep, i've done that a couple times
still nothing in the database
very odd
d
default$default is your database!
service$stage format
c
sorry i was replying to main by mistake
so now i can see my tables
.
but unfortunately still no dice on executeRaw
but
d
AFAIK this varies between MySQL and Postgres! For mysql schema =>
service@stage
, let me look up what it is in postgres!
c
ah, ok... so this is interesting. it appears to work if i put the table name in quotes
d
indeed, it is a postgres syntax thing!
I think
c
ok
success!
🎉 1
d
but can you please create an issue about usability... with your findings.. and confusion! then we can hope to improve it 🙂
c
yep, i saw another issue to document raw sql execution so i will add to that
d
thanks
n
do you have a link, @cedric? would love to read on
c
sure thing, i wrote up most of my findings here: https://github.com/prisma/prisma/issues/3300#issuecomment-430696015
and then i referenced that comment here: https://github.com/prisma/prisma-content-feedback/issues/9