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

Added SQLite event store the ability to create connection #178

Conversation

davecosec
Copy link
Collaborator

Moved creation of db by location to construction

Moved creation of db by location to construction
@davecosec davecosec changed the title Added eventstore the ability to create connection from path Added eventstore the ability to create connection Jan 21, 2025
@oskardudycz oskardudycz changed the title Added eventstore the ability to create connection Added SQLite event store the ability to create connection Jan 22, 2025
@oskardudycz oskardudycz added this to the 0.27.0 milestone Jan 22, 2025
autoMigration?: 'None' | 'CreateOrUpdate';
};
};
export type SQLiteEventStoreOptions =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: @davecosec can we also allow passing sqlite3.Database? I think that will be useful to do without passing the sqliteConnection. I know that in the future we'll allow more providers, but for now we have only one, so I think that this would be accessible to add.

Copy link
Collaborator

@oskardudycz oskardudycz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davecosec, that's good work. I added some small requests to adjust the database injection and lifetime management. Once that's made, I'm happy to pull that in.

Feel free to ask if I wasn't precise in the comments. 🙂

@oskardudycz oskardudycz force-pushed the main branch 2 times, most recently from 697ae3d to 3eda928 Compare January 31, 2025 17:58
}

if (options?.databaseLocation == null) {
throw new Error('Database location is not set');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONCERN: Wouldn't it be better to make database location required? Then, on the compiler level, we would make it impossible to provide the wrong value. The alternative is to keep it optional and use in-memory if not provided, which I think is fine.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the fallback.

@oskardudycz
Copy link
Collaborator

@davecosec could you check why this test is faling in CI?

# FATAL ERROR: Error::New napi_get_last_error_info
# ----- Native stack trace -----
#  1: 0xca5580 node::Abort() [/opt/hostedtoolcache/node/20.11.1/x64/bin/node]
#  2: 0xb78101 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [/opt/hostedtoolcache/node/20.11.1/x64/bin/node]
#  3: 0xc64b55  [/opt/hostedtoolcache/node/20.11.1/x64/bin/node]
#  4: 0x7f4277628a1e  [/home/runner/work/emmett/emmett/src/node_modules/sqlite3/build/Release/node_sqlite3.node]
#  5: 0x7f4277628d5d Napi::Error::New(napi_env__*) [/home/runner/work/emmett/emmett/src/node_modules/sqlite3/build/Release/node_sqlite3.node]
#  6: 0x7f427763c971 node_sqlite3::Database::Baton::Baton(node_sqlite3::Database*, Napi::Function) [/home/runner/work/emmett/emmett/src/node_modules/sqlite3/build/Release/node_sqlite3.node]
#  7: 0x7f4277633a84 node_sqlite3::Database::Database(Napi::CallbackInfo const&) [/home/runner/work/emmett/emmett/src/node_modules/sqlite3/build/Release/node_sqlite3.node]
#  8: 0x7f427763d15e Napi::ObjectWrap<node_sqlite3::Database>::ConstructorCallbackWrapper(napi_env__*, napi_callback_info__*) [/home/runner/work/emmett/emmett/src/node_modules/sqlite3/build/Release/node_sqlite3.node]
#  9: 0xc408d9  [/opt/hostedtoolcache/node/20.11.1/x64/bin/node]
# 10: 0xf328df v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/opt/hostedtoolcache/node/20.11.1/x64/bin/node]
# 11: 0xf32e95  [/opt/hostedtoolcache/node/20.11.1/x64/bin/node]
# 12: 0xf335b3 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [/opt/hostedtoolcache/node/20.11.1/x64/bin/node]
# 13: 0x193cdf6  [/opt/hostedtoolcache/node/20.11.1/x64/bin/node]
# ----- JavaScript stack trace -----
# 1: sqliteConnection (file:///home/runner/work/emmett/emmett/src/packages/emmett-sqlite/src/sqliteConnection.ts:1:411)
# 2: file:///home/runner/work/emmett/emmett/src/packages/emmett-sqlite/src/eventStore/SQLiteEventStore.e2e.spec.ts:1:1805
# 3: runInAsyncScope (node:async_hooks:206:9)
# 4: run (node:internal/test_runner/test:631:25)
# 5: processPendingSubtests (node:internal/test_runner/test:374:18)
# 6: postRun (node:internal/test_runner/test:715:19)
# 7: node:internal/test_runner/harness:76:10
# 8: emit (node:events:518:28)
# 9: node:internal/process/execution:178:25
# Subtest: /home/runner/work/emmett/emmett/src/packages/emmett-sqlite/src/eventStore/SQLiteEventStore.e2e.spec.ts
not ok 8 - /home/runner/work/emmett/emmett/src/packages/emmett-sqlite/src/eventStore/SQLiteEventStore.e2e.spec.ts
  ---
  duration_ms: 1535.594155
  location: '/home/runner/work/emmett/emmett/src/packages/emmett-sqlite/src/eventStore/SQLiteEventStore.e2e.spec.ts:1:1'
  failureType: 'testCodeFailure'
  signal: 'SIGABRT'
  error: 'test failed'
  code: 'ERR_TEST_FAILURE'

@oskardudycz oskardudycz force-pushed the sqlite-updated-event-store-to-allow-for-connection-creation branch 3 times, most recently from acf1d20 to a974b8e Compare February 11, 2025 13:52
E2E tests were failing, as there was no nested database folder in the 'testing' subdirectory. Probably locally it was created, but git is not commiting empty folders. Adjusted not to require such nesting.

Fixed also TS config to compile SQLite package correctly, as some entries were missing. After that fixed the common errors.

Added a helper withConnection to streamline the connection management. Now it also uses correctly close in finalize, instead of double closing in case of error.

Renamed location to fileName to follow the SQLite naming convention, made it also optional with fallback to in memory.

Removed absolute file path and custom, as it won't allow easily passing the filenames without casting that are not typed manually.
@oskardudycz oskardudycz force-pushed the sqlite-updated-event-store-to-allow-for-connection-creation branch from a974b8e to 913f5e6 Compare February 11, 2025 13:59
@oskardudycz oskardudycz merged commit 67b4f2c into event-driven-io:main Feb 11, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants