question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve type conversion and responses for raw queries

See original GitHub issue

Bug description

I am using prisma.$queryRaw for creating mapbox vector tiles from db using PostgreSQL and PostGIS image I expect get node.js Buffer in mvt field but prisma query engine serialize the db response to text and I can’t correctly convert it to a buffer

Buffer.from(data.mvt as string, 'binary')

is not help!

image

How to reproduce

Expected behavior

prism should return a Buffer in place of text for binary data

Prisma information

Environment & setup

  • OS: PopOS(Ubuntu 20.10)
  • Database: PostgreSQL
  • Node.js version: v14.15.1
  • Prisma version:
@prisma/cli          : 2.13.0
@prisma/client       : 2.12.1
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine 833ab05d2a20e822f6736a39a27de4fc8f6b3e49 (at node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli 833ab05d2a20e822f6736a39a27de4fc8f6b3e49 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 833ab05d2a20e822f6736a39a27de4fc8f6b3e49 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt 833ab05d2a20e822f6736a39a27de4fc8f6b3e49 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Studio               : 0.329.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pimeyscommented, Jan 27, 2021

Example:

let r#type = match &p_value {
    quaint::Value::Integer(_) => "integer",
    quaint::Value::Float(_) => "float",
    quaint::Value::Double(_) => "double",
    quaint::Value::Text(_) => "text",
    quaint::Value::Enum(_) => "enum",
    quaint::Value::Bytes(_) => "bytes",
    quaint::Value::Boolean(_) => "bool",
    quaint::Value::Char(_) => "char",
    quaint::Value::Array(_) => todo!(),
    quaint::Value::Numeric(_) => "numeric",
    quaint::Value::Json(_) => "json",
    quaint::Value::Xml(_) => "xml",
    quaint::Value::Uuid(_) => "uuid",
    quaint::Value::DateTime(_) => "datetime",
    quaint::Value::Date(_) => "date",
    quaint::Value::Time(_) => "time",
};
inner_object.insert(r#type.into(), Value::from(p_value));
object.insert(column_name, Value::Object(inner_object));

You get the point.

1reaction
paulm17commented, Jan 18, 2021

Sorry to barge in. But I have exact the same issue using $queryRaw.

I’m using ulid to generate my ids.

https://www.npmjs.com/package/ulid

My table:

model anki_lists {
id         Bytes        @id @db.Binary(26)
name       String?      @db.VarChar(255)
created_at DateTime?    @db.Timestamp(0)
updated_at DateTime?    @db.Timestamp(0)
deleted_at DateTime?    @db.Timestamp(0)
anki_cards anki_cards[]
}

I expect to get back something like:

+----------------------------+------------+
| id                         | name       |
+----------------------------+------------+
| 01esy4337ym3yknze675g3grhy | Pimsleur 1 |
| 01et07hamgxc9e92e72mq78wph | Pimsleur 2 |
+----------------------------+------------+
2 rows in set (0.023 sec)

Except when I console log the result of the raw query:

[
{ id: 'MDFlc3k0MzM3eW0zeWtuemU2NzVnM2dyaHk=', name: 'Pimsleur 1' },
{ id: 'MDFldDA3aGFtZ3hjOWU5MmU3Mm1xNzh3cGg=', name: 'Pimsleur 2' }
]

I should be receiving a buffer instead of an encoded string?

Let me know what you need to solve this issue.

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL Server Data Type Conversion Methods and performance ...
This artcile explores the SQL Server Data type conversion method and their performance comparison.
Read more >
Scala Slick implicit conversion of multiple types in raw SQL ...
I haven't been able to find a solution to the implicit conversion problem, but I've found a workaround using more traditional slick syntax,...
Read more >
SQL Query Optimization: 12 Useful Performance Tuning Tips ...
Read the tutorial to learn more about SQL Server performance tuning best practices that help greater improve SQL Server query optimization.
Read more >
Raw Queries - Sequelize
As there are often use cases in which it is just easier to execute raw / already prepared SQL queries, you can use...
Read more >
Data type conversion (Database Engine) - SQL Server
DECLARE @string VARCHAR(10); SET @string = 1; SELECT @string + ' is a string.' The int value of 1 is converted to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found