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

Cannot connect Prisma Client to SQLite Cloud DB #99

Open
unatarajan opened this issue Jul 10, 2024 · 0 comments
Open

Cannot connect Prisma Client to SQLite Cloud DB #99

unatarajan opened this issue Jul 10, 2024 · 0 comments
Labels
friction Product sticking/ pain points

Comments

@unatarajan
Copy link

unatarajan commented Jul 10, 2024

Validation/ Reproduction Steps

  1. Initialize a new TypeScript/ Node.js/ Prisma project using the following instructions:
mkdir sqlc-quickstart
cd sqlc-quickstart

npm init -y
npm install typescript ts-node @types/node --save-dev
npx tsc --init

npm install prisma --save-dev
npx prisma init
  1. In .env, set DATABASE_URL to your SQLite Cloud DB connection string. (No need to install dotenv pkg.)
  • I tried 2 different connection strings: sqlitecloud://chtwalrwiz.sqlite.cloud:8860?apikey=lEN1TsCrDYlEFYia7VSjtme8HTFV3aHbXDy7rRBXEhM and sqlitecloud://upasana-admin:[email protected]:8860/chinook.sqlite. Both produced the errors documented in steps 3 and 4.
  1. In schema.prisma, set datasource db's provider to sqlitecloud.
    Run npx prisma db pull to connect to and introspect the DB.
    Get error: Datasource provider not known: "sqlitecloud".
    This makes sense, as Prisma ORM supports only these 6 datasource providers: postgresql, mysql, sqlite, sqlserver, mongodb, cockroachdb.

  2. In schema.prisma, set datasource db's provider to sqlite.
    Run npx prisma db pull.
    Get error: Error validating datasource 'db': the URL must start with the protocol 'file:'.
    Also makes sense, as a SQLite DB is an embedded file, not cloud server. Connecting a Prisma ORM client to a SQLite Cloud database directly isn't supported.

Notes

  • None of the other providers work/ are appropriate for this use case. All of them expect a different starting protocol, and the DB connection string uses sqlitecloud protocol.
  • GPT workarounds/ suggestions:
    a. Set up a proxy server (i.e. Node.js/ Express). Connect the proxy to the SQLite Cloud database. Modify the Prisma client to interact with the endpoints exposed by the proxy server, which would handle queries and send responses back to the client.
    b. Use a different ORM or DB client. sqlite3 or better-sqlite3 might be adapted to work with SQLite Cloud.
    c. Migrate SQLite Cloud DB(s) to a Prisma-supported provider.

(a) may be viable, but to be really useful, I'd/ we'd basically have to recreate the entire ORM API in Express.
(b) means give up using Prisma.
(c) means give up using SQLite Cloud.

Related Issue(s)

sample content / JavaScript & Prisma

Screenshots & Videos

N/A.
I'd attach my own project to this comment, but GitHub doesn't allow it.

@unatarajan unatarajan added the friction Product sticking/ pain points label Jul 10, 2024
@unatarajan unatarajan reopened this Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
friction Product sticking/ pain points
Projects
None yet
Development

No branches or pull requests

1 participant