libsql / libsql-node-sqlite3

node-sqlite3 compatible API for libSQL
MIT License
12 stars 1 forks source link

turn PRAGMA to a noop #8

Open rhildred opened 1 year ago

rhildred commented 1 year ago

I am trying to get turso working with sequelize. I got mostly through the example:

    it("url test.sqlite", async () => {
        const sequelize = new Cloudflare2Sequelize({url: `${process.env.SEQUELIZE_NAME}?authToken=${process.env.SEQUELIZE_TOKEN}`, mode: SQLite.OPEN_READWRITE | SQLite.OPEN_CREATE | SQLite.OPEN_FULLMUTEX});
        const User = sequelize.define('User', {
            username: DataTypes.STRING,
            birthday: DataTypes.DATE,
          });
          await sequelize.sync();
          const jane = await User.create({
            username: 'janedoe',
            birthday: new Date('1980-06-20'),
          });

          const users = await User.findAll();

          expect(users.length).toBeGreaterThan(0);
    });

by turning sqlite PRAGMA into a noop. Hence the pull request.

Unfortunately I am getting reset errors now:

SequelizeDatabaseError: request to https://testsqlite-rhildred.turso.io/v2/pipeline failed, reason: socket hang up
 ❯ node_modules/sequelize/src/dialects/sqlite/query.js:236:27
 ❯ Database.serialize node_modules/@rhildred/sqlite3/lib/database.js:171:13
 ❯ node_modules/sequelize/src/dialects/sqlite/query.js:234:50
 ❯ Query.run node_modules/sequelize/src/dialects/sqlite/query.js:234:12
 ❯ node_modules/sequelize/src/sequelize.js:650:28
 ❯ SQLiteQueryInterface.select node_modules/sequelize/src/dialects/abstract/query-interface.js:1001:12
 ❯ Function.findAll node_modules/sequelize/src/model.js:1824:21
 ❯ __tests__/local.test.js:44:25
     42|           });
     43|         
     44|           const users = await User.findAll();
       |                         ^
     45|         
     46|           expect(users.length).toBeGreaterThan(0);

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: {
  "original": {
    "code": "ECONNRESET",
    "constructor": "Function<FetchError>",
    "errno": "ECONNRESET",
    "message": "request to https://testsqlite-rhildred.turso.io/v2/pipeline failed, reason: socket hang up",
    "name": "FetchError",
    "sql": "SELECT `id`, `username`, `birthday`, `createdAt`, `updatedAt` FROM `Users` AS `User`;",
    "stack": "FetchError: request to https://testsqlite-rhildred.turso.io/v2/pipeline failed, reason: socket hang up
    at ClientRequest.<anonymous> (/Users/rhildred/source/July15cloudflare2sequelize/node_modules/node-fetch/lib/index.js:1505:11)
    at ClientRequest.emit (node:events:513:28)
    at TLSSocket.socketOnEnd (node:_http_client:512:9)
    at TLSSocket.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)",
    "toString": "Function<toString>",
    "type": "system",
  },
  "parameters": {},
  "parent": {
    "code": "ECONNRESET",
    "constructor": "Function<FetchError>",
    "errno": "ECONNRESET",
    "message": "request to https://testsqlite-rhildred.turso.io/v2/pipeline failed, reason: socket hang up",
    "name": "FetchError",
    "sql": "SELECT `id`, `username`, `birthday`, `createdAt`, `updatedAt` FROM `Users` AS `User`;",
    "stack": "FetchError: request to https://testsqlite-rhildred.turso.io/v2/pipeline failed, reason: socket hang up
    at ClientRequest.<anonymous> (/Users/rhildred/source/July15cloudflare2sequelize/node_modules/node-fetch/lib/index.js:1505:11)
    at ClientRequest.emit (node:events:513:28)
    at TLSSocket.socketOnEnd (node:_http_client:512:9)
    at TLSSocket.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)",
    "toString": "Function<toString>",
    "type": "system",
  },
  "sql": "SELECT `id`, `username`, `birthday`, `createdAt`, `updatedAt` FROM `Users` AS `User`;",
} 

If I repeat the test without cleaning up, I get further and further as though there is just a missing await in there somewhere.

My sequelize tests, as well as a small adapter are at https://github.com/diy-pwa/cloudflare2sequelize. I am super excited about using sequelize on cloudflare with turso as the database.

honzasp commented 1 year ago

Hi, thank you for your interest in this library! :) Do you have some more detailed information about the errors from PRAGMAs that you encountered? We might be able to fix them. I'm afraid that turning all PRAGMAs into noops in the library is not a solution that we can merge.

rhildred commented 1 year ago

Hi, Thanks for your quick reply. The only PRAGMA that I saw so far was PRAGMA INDEX_LIST(Users). The sqlite documentation mentioned that PRAGMAs were sqlite specific so I assumed libsql didn't implement or need them but fair enough about turning all Pragmas into no-ops.

rhildred commented 1 year ago

I guess that I should open an issue about the reset errors.

rhildred commented 1 year ago

never mind about the reset errors. My tests ran through this morning with the PRAGMA no-op in my fork.