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

turn PRAGMA to a noop #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

turn PRAGMA to a noop #8

wants to merge 1 commit into from

Conversation

rhildred
Copy link

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
Copy link
Contributor

honzasp commented Jul 17, 2023

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
Copy link
Author

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
Copy link
Author

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

@rhildred
Copy link
Author

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

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.

3 participants