sebastianwessel / surrealdb-client-generator

Tool which generates a typescript client for SurrealDB and zod schema of a given database
MIT License
77 stars 12 forks source link

SurrealDB 2 functions are not allowed #64

Closed zvictor closed 2 months ago

zvictor commented 2 months ago

SurrealDB 2 has new functions that did not exist before.

When running surrealdb-client-generator in a code with such functions, it fails. As an example, record::id causes an error to be thrown.

Record functions before SurrealDB 2.0 were located inside the module meta. As of version 2.0, these functions are now part of SurrealDB's record functions.

./node_modules/.bin/surql-gen --no-generateClient
No config file found.
Starting temporary SurrealDB instance
Temporary SurrealDB instance started at http://localhost:33789
Connecting to database
Connected to database successfully

πŸ”΄ This did not work as expected πŸ₯Ί
πŸ”΄ I am sorry that this happened, and I kindly ask for your help to fix this.
πŸ”΄
πŸ”΄ Please open an issue here:
πŸ”΄ πŸ‘‰ https://github.com/sebastianwessel/surrealdb-client-generator/issues
πŸ”΄
πŸ”΄ Please copy & paste the following code into the ticket:
=====
ResponseError: There was a problem with the database: Parse error: Failed to parse query at line 109 column 61 expected function arguments
    |
109 | ...ice(record::id($value.id), 0, 4);
    |              ^

    at Surreal.query_raw (/node_modules/.pnpm/surrealdb@1.0.0-beta.21_tslib@2.7.0_typescript@5.6.2_ws@8.18.0_bufferutil@4.0.8_utf-8-validate@6.0.4_/node_modules/surrealdb/dist/index.cjs:1:45589)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Surreal.query (/node_modules/.pnpm/surrealdb@1.0.0-beta.21_tslib@2.7.0_typescript@5.6.2_ws@8.18.0_bufferutil@4.0.8_utf-8-validate@6.0.4_/node_modules/surrealdb/dist/index.cjs:1:45244)
    at async insertDefinitions (/node_modules/.pnpm/@sebastianwessel+surql-gen@2.6.1_tslib@2.7.0_typescript@5.6.2_ws@8.18.0_bufferutil@4.0.8_utf-8-validate@6.0.4_/node_modules/@sebastianwessel/surql-gen/dist/index.js:92:3)
    at async main (/node_modules/.pnpm/@sebastianwessel+surql-gen@2.6.1_tslib@2.7.0_typescript@5.6.2_ws@8.18.0_bufferutil@4.0.8_utf-8-validate@6.0.4_/node_modules/@sebastianwessel/surql-gen/dist/index.js:1006:9)
sebastianwessel commented 2 months ago

From first guess, looks like an issue in the surrealdb (client)

hammo92 commented 2 months ago

@zvictor did you provide a schema file? When a schema file is used we spin up an instance with docker using the latest main version, if you want to use v2 then you'll need to provide the correct image for the beta -i, --surrealImage SurrealDB docker image (default: surrealdb/surrealdb:latest)

zvictor commented 2 months ago

of course. the record::id is part of the schema. Once I get back to my computer I will reply with an example schema

hammo92 commented 2 months ago

of course. the record::id is part of the schema. Once I get back to my computer I will reply with an example schema

Okay, try adding the -i flag with the nightly image surrealdb/surrealdb:nightly see if that fixes the issue for you.

zvictor commented 2 months ago

That works! I am sorry I didn't notice the --surrealImage had been added...

Morever, to my surprise, using --surrealImage surrealdb/surrealdb:nightly also gets rid of #63.