Skip to content

feat(sqlite): implement sqlite in wasip2 #25

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

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

Conversation

adamreese
Copy link
Contributor

No description provided.

@adamreese adamreese marked this pull request as ready for review July 18, 2025 18:49
@itowlson itowlson requested a review from rajatjindal July 29, 2025 04:29
@itowlson
Copy link
Contributor

Worth squashing commits?

@adamreese
Copy link
Contributor Author

Squished

Copy link
Contributor

@itowlson itowlson left a comment

Choose a reason for hiding this comment

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

This looks like a super smooth experience! I left a few comments but I think they're nits except possibly the build command line?

allowed_outbound_hosts = []
sqlite_databases = ["default"]
[component.sqlite.build]
command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -o main.wasm main.go"
Copy link
Contributor

Choose a reason for hiding this comment

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

Will the $(go list ...) work on Windows?

Copy link
Member

Choose a reason for hiding this comment

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

hmm, go list should work, but not sure about $(go list...). I had opened a ticket ydnar/wasi-http-go#22 to check with other folks if there is a better way to do this.

case "text":
ret[i] = *v.Text()
case "blob":
// TODO: check this
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this now TODONE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, It's not. For some reason blob columns are being returned as text. I'm still tracing it.

rows := &rows{
columns: cols,
rows: allrows,
len: int(rowLen),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to hold this separately - e.g. is len(allrows) expensive to calculate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was copy pasta that I left in because it spares the cost of len(allrows) on each iteration of .Next(). TBH I'm not sure if it saves all that much.

db := sqlite.Open("default")
defer db.Close()

_, err := db.Query("REPLACE INTO pets VALUES (4, 'Maya', ?, false);", "bananas")
Copy link
Member

Choose a reason for hiding this comment

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

could we pls also add init schema in this example. I tried running it and ran into no such table: pets. Also if you think that is out of scope, maybe a small readme file to initiate that db manually would be great.

Copy link
Member

Choose a reason for hiding this comment

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

actually now that i tried creating table myself, its not that hard.

sqlite3 .spin/sqlite_db.db
<copy paste from db/pets.sql>

so feel free to ignore my previous comment 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Spin Can Do That! spin up --sqlite @db/pets.sql

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.

4 participants