Skip to content

feat: redundant storage#13

Open
Le0Developer wants to merge 8 commits into
WalshyDev:mainfrom
Le0Developer:feat/redundant-storage
Open

feat: redundant storage#13
Le0Developer wants to merge 8 commits into
WalshyDev:mainfrom
Le0Developer:feat/redundant-storage

Conversation

@Le0Developer

@Le0Developer Le0Developer commented Nov 4, 2023

Copy link
Copy Markdown
Contributor

KV can go down. So lets also use D1 and R2.

Note: I didn't test this I have tested this

@WalshyDev WalshyDev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

ty! I was planning to do these changes as well so appreciate this

Comment thread README.md Outdated
Comment thread README.md
```

To setup D1, you need to run the following SQL statement:
`CREATE TABLE IF NOT EXISTS KV (key TEXT UNIQUE, value TEXT)`

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
`CREATE TABLE IF NOT EXISTS KV (key TEXT UNIQUE, value TEXT)`
`CREATE TABLE IF NOT EXISTS incidents (key TEXT UNIQUE, value JSON)`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is SQLite, JSON will actually be mapped to NUMERIC.
See datatype3 3.1:

  1. If the declared type contains the string "INT" then it is assigned INTEGER affinity.
  2. If the declared type of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity.
  3. If the declared type for a column contains the string "BLOB" or if no type is specified then the column has affinity BLOB.
  4. If the declared type for a column contains any of the strings "REAL", "FLOA", or "DOUB" then the column has REAL affinity.
  5. Otherwise, the affinity is NUMERIC.

Comment thread src/storage.ts
env.KV && env.KV.put(key, data),
env.D1 &&
env.D1.prepare(
`INSERT INTO KV(key, value) VALUES(?1, ?2) ON CONFLICT(key) DO UPDATE SET value = ?2`,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
`INSERT INTO KV(key, value) VALUES(?1, ?2) ON CONFLICT(key) DO UPDATE SET value = ?2`,
`INSERT INTO incidents(key, value) VALUES(?1, ?2) ON CONFLICT(key) DO UPDATE SET value = ?2`,

Comment thread src/storage.ts
const rawValues = await Promise.allSettled([
env.KV && env.KV.get(key),
env.D1 &&
env.D1.prepare(`SELECT value FROM KV WHERE key = ?`).bind(key).first("value"),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
env.D1.prepare(`SELECT value FROM KV WHERE key = ?`).bind(key).first("value"),
env.D1.prepare(`SELECT value FROM incidents WHERE key = ?`).bind(key).first("value"),

Co-authored-by: Daniel Walsh <walshydev@gmail.com>
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