Skip to content

Cannot connect Prisma Client to SQLite Cloud DB #99

Open
@unatarajan

Description

@unatarajan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    frictionProduct sticking/ pain points

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions