Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conversion for blob, binary and bit type #17

Merged
merged 5 commits into from
Feb 27, 2024

Conversation

shiyuhang0
Copy link
Collaborator

@shiyuhang0 shiyuhang0 commented Feb 23, 2024

TiDB Cloud serverless driver supports Unit8Array as input in v0.1.0. But it has a break change in v0.1.0:

  • It returns Uint8array rather than string for blob, binary and bit type

Prisma Accept string and array for these types. Thus, conversion error occurs.

This PR fix this.

Test

Test succeed locally

schema and codes:

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["driverAdapters"]
}

datasource db {
  provider     = "mysql"
  url          = env("DATABASE_URL")
}

model user {
  id    Int     @id @default(autoincrement())
  email String? @unique(map: "uniq_email") @db.VarChar(255)
  name  String? @db.VarChar(255)
  bytes Bytes?
}


import { connect } from '@tidbcloud/serverless';
import { PrismaTiDBCloud } from '@tidbcloud/prisma-adapter';
import { PrismaClient } from '@prisma/client';
import dotenv from 'dotenv';
import { fetch } from 'undici'

// setup
dotenv.config();
const connectionString = "xxx";
const connection = connect({ url: connectionString ,fetch});
const adapter = new PrismaTiDBCloud(connection);
const prisma = new PrismaClient({ adapter });


await prisma.user.deleteMany({})
// insert
const user = await prisma.user.create({
  data: {
    id: 1,
    email: '[email protected]',
    name: 'test',
    bytes: Buffer.from('FSDF',"base64"),
  },
})
console.log(user)

result:

{
  id: 1,
  email: '[email protected]',
  name: 'test',
  bytes: <Buffer 15 20 c5>
}

Other

This PR format the whole codes

@zhangyangyu zhangyangyu self-requested a review February 26, 2024 16:51
@shiyuhang0 shiyuhang0 merged commit 5d0059a into tidbcloud:main Feb 27, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants