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

feat(store-sync): sync to sqlite #1185

Merged
merged 7 commits into from
Jul 21, 2023
Merged

feat(store-sync): sync to sqlite #1185

merged 7 commits into from
Jul 21, 2023

Conversation

holic
Copy link
Member

@holic holic commented Jul 20, 2023

pulled out of #1113

@changeset-bot
Copy link

changeset-bot bot commented Jul 20, 2023

🦋 Changeset detected

Latest commit: 3502df6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
@latticexyz/store-sync Major
@latticexyz/block-logs-stream Major
@latticexyz/cli Major
@latticexyz/common Major
@latticexyz/config Major
create-mud Major
@latticexyz/dev-tools Major
@latticexyz/ecs-browser Major
@latticexyz/gas-report Major
@latticexyz/network Major
@latticexyz/noise Major
@latticexyz/phaserx Major
@latticexyz/protocol-parser Major
@latticexyz/react Major
@latticexyz/recs Major
@latticexyz/schema-type Major
@latticexyz/services Major
@latticexyz/solecs Major
solhint-config-mud Major
solhint-plugin-mud Major
@latticexyz/std-client Major
@latticexyz/std-contracts Major
@latticexyz/store-cache Major
@latticexyz/store Major
@latticexyz/utils Major
@latticexyz/world Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@holic holic marked this pull request as ready for review July 20, 2023 14:01
@holic holic requested a review from alvrs as a code owner July 20, 2023 14:01
@holic holic changed the title feat(store-sync): add utils to sync to sqlite feat(store-sync): sync to sqlite Jul 20, 2023
so they can be used outside of block logs stream if needed
tx.insert(chainState)
.values({
schemaVersion,
chainId: publicClient.chain.id,
Copy link
Member

Choose a reason for hiding this comment

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

it seems like the only reason we need a viem publicClient in here is for the chain id - would it be sufficient to just pass in the chain id?

Copy link
Member Author

@holic holic Jul 21, 2023

Choose a reason for hiding this comment

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

there's a TODO above to ask the RPC for missing tables: https://github.com/latticexyz/mud/pull/1185/files#diff-57e424c9e734e8f90ffab2a6b59de8a4b9134d0f646207b502a555da87c3402fR62

I was just deferring this for now because it'll be soon refactored with the table registration changes.

Copy link
Member

Choose a reason for hiding this comment

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

gotcha, makes sense

export function sqliteTableToSql(table: SQLiteTableWithColumns<any>): string {
const tableName = getTableName(table);

// db.schema.dropTable(tableName).ifExists().compile();
Copy link
Member

Choose a reason for hiding this comment

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

do we need this or should we remove the comment?

col = col.notNull();
}
if (column.hasDefault && typeof column.default !== "undefined") {
// col = col.defaultTo(column.mapToDriverValue(column.default));
Copy link
Member

Choose a reason for hiding this comment

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

to we need this or should we remove the comment?


await blockLogsToStorage(storageAdapter)({
blockNumber: 5448n,
logs: [
Copy link
Member Author

Choose a reason for hiding this comment

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

This kind of tests both blockLogsToStorage and sqliteStorage in one because it used to be combined (we'd wrap blockLogsToStorage).

I feel like "integration" tests like this tend to be more accurate/useful so I kept it, but happy to relocate and save this file for more unit tests.

@holic holic merged commit 69a96f1 into main Jul 21, 2023
@holic holic deleted the holic/block-logs-to-sqlite branch July 21, 2023 09:48
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.

2 participants