libsql / libsql-node-sqlite3

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

connection reset errors #9

Closed rhildred closed 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);
    });

Unfortunately, I am getting socket errors even though the table is being created and data inserted into it.

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.

rhildred commented 1 year ago

Today it works! My tests run through.