Skip to content

Commit 6a844fb

Browse files
authored
updated sql.wit.md, and README.md (#2)
* commenting out wit-abi 'cause of worlds Signed-off-by: danbugs <[email protected]> * updated README up until before TOC Signed-off-by: danbugs <[email protected]> * updated sql.wit.md file according to discussions w/ @itowlson Signed-off-by: danbugs <[email protected]> * forgot to add title to README Signed-off-by: danbugs <[email protected]> * added wit label on worlds code block Signed-off-by: danbugs <[email protected]> * fixing quick typo Signed-off-by: danbugs <[email protected]> * typo Signed-off-by: danbugs <[email protected]> * added null type to data-types Signed-off-by: danbugs <[email protected]> * added unsigned/signed short and longs Signed-off-by: danbugs <[email protected]> * typos in sql.wit.md, andmostly completed README Signed-off-by: danbugs <[email protected]> * fixed typo, some renames, and updated examples Signed-off-by: danbugs <[email protected]> * change stream to list Signed-off-by: danbugs <[email protected]> --------- Signed-off-by: danbugs <[email protected]>
1 parent 16f3f56 commit 6a844fb

File tree

5 files changed

+111
-89
lines changed

5 files changed

+111
-89
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v2
14-
- uses: WebAssembly/wit-abi-up-to-date@v6
15-
with:
16-
wit-abi-tag: wit-abi-0.6.0
14+
# - uses: WebAssembly/wit-abi-up-to-date@v6
15+
# with:
16+
# wit-abi-tag: wit-abi-0.6.0

README.md

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
1-
# [Example WASI proposal]
2-
3-
This template can be used to start a new proposal, which can then be proposed in the WASI Subgroup meetings.
4-
5-
The sections below are recommended. However, every proposal is different, and the community can help you flesh out the proposal, so don't block on having something filled in for each one of them.
6-
7-
Thank you to the W3C Privacy CG for the [inspiration](https://github.com/privacycg/template)!
8-
9-
# [Title]
1+
# `wasi-sql`
102

113
A proposed [WebAssembly System Interface](https://github.com/WebAssembly/WASI) API.
124

135
### Current Phase
146

15-
[Fill in the current phase, e.g. Phase 1]
7+
`wasi-messaging` is currently in [Phase 1](https://github.com/WebAssembly/WASI/blob/main/Proposals.md#phase-1---feature-proposal-cg).
168

179
### Champions
1810

19-
- [Champion 1]
20-
- [Champion 2]
21-
- [etc.]
11+
- [Dan Chiarlone](https://github.com/danbugs)
12+
- [David Justice](https://github.com/devigned)
13+
- [Jiaxiao Zhou](https://github.com/Mossaka)
2214

2315
### Phase 4 Advancement Criteria
2416

25-
TODO before entering Phase 2.
17+
`wasi-sql` should have at least two implementations (i.e., from service providers, and or cloud providers), and, at the very minimum, pass the testsuite for Windows, Linux, and MacOS.
2618

27-
## Table of Contents [if the explainer is longer than one printed page]
19+
## Table of Contents
2820

2921
- [Introduction](#introduction)
3022
- [Goals [or Motivating Use Cases, or Scenarios]](#goals-or-motivating-use-cases-or-scenarios)
@@ -43,27 +35,54 @@ TODO before entering Phase 2.
4335

4436
### Introduction
4537

46-
[The "executive summary" or "abstract". Explain in a few sentences what the goals of the project are, and a brief overview of how the solution works. This should be no more than 1-2 paragraphs.]
38+
The `wasi-sql` interface allows WebAssembly programs to interact with SQL databases in a generic and safe way. It provides functions for querying and modifying data, using prepared statements and handling errors. The interface is flexible and consistent, supporting various SQL flavors.
39+
40+
### Goals
4741

48-
### Goals [or Motivating Use Cases, or Scenarios]
42+
The `wasi-sql` interface aims to provide a consistent and easy-to-use way for WebAssembly programs to access and manipulate data stored in SQL databases. It targets the features commonly used by 80% of user applications. By focusing on commonly used features, the interface aims to provide a simple and reliable way to build stateful services that access SQL databases.
4943

50-
[What is the end-user need which this project aims to address?]
44+
The `wasi-sql` interface abstracts away specific SQL flavors and database APIs, allowing WebAssembly programs to be portable across different SQL databases that support the interface. It also abstracts away the network stack, allowing WebAssembly programs to access SQL databases without worrying about the specific network protocol used. This allows users to focus on building their applications, rather than communication details with the database.
5145

5246
### Non-goals
5347

54-
[If there are "adjacent" goals which may appear to be in scope but aren't, enumerate them here. This section may be fleshed out as your design progresses and you encounter necessary technical and other trade-offs.]
48+
- The `wasi-sql` interface does not aim to provide support for every possible feature of SQL databases. Instead, it focuses on the features that are commonly used by 80% of user applications.
49+
- The `wasi-sql` interface does not aim to provide support for specific database APIs or network protocols. It abstracts away these implementation details to allow WebAssembly programs to be portable across different SQL databases that support the interface.
50+
- The `wasi-sql` interface does not aim to address control-plane behavior or functionality, such as cluster management, monitoring, data consistency, replication, or sharding. These are provider-specific and are not specified by the wasi-sql interface.
5551

5652
### API walk-through
5753

5854
[Walk through of how someone would use this API.]
5955

60-
#### [Use case 1]
56+
#### Use case 1: Query data from a table
6157

62-
[Provide example code snippets and diagrams explaining how the API would be used to solve the given problem]
58+
Imagine you have a WebAssembly program that needs to query data from a table in a SQL database. The following Rust code shows how you can use the `wasi-sql` interface to execute a SELECT statement and iterate over the resulting rows.
6359

64-
#### [Use case 2]
60+
```rs
61+
// Create a prepared statement
62+
let stmt = sql::statement::prepare("SELECT * FROM users WHERE name = ? AND age = ?", vec!["John Doe", "32"])?;
6563

66-
[etc.]
64+
// Execute the query and get the stream of rows
65+
let result_stream = sql::query(stmt)?;
66+
67+
// Iterate over the rows in the stream
68+
for row in result_stream {
69+
// Print the column names and values for the current row
70+
println!("Column name: {:?}", row.field_name);
71+
println!("Value: {:?}", row.value);
72+
}
73+
```
74+
75+
#### Use case 2: Insert data into a table
76+
77+
Imagine you have a WebAssembly program that needs to insert a row into a table in a SQL database. The following Rust code shows how you can use the wasi-sql interface to execute an INSERT statement.
78+
79+
```rs
80+
// Create a prepared statement
81+
let stmt = sql::statement::prepare("INSERT INTO users (name, age) VALUES (?, ?)", vec!["Jane Doe", "30"])?;
82+
83+
// Execute the statement
84+
sql::exec(stmt)?;
85+
```
6786

6887
### Detailed design discussion
6988

proposal-template.abi.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

proposal-template.wit.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

sql.wit.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# `wasi-sql` API
2+
3+
## Interfaces
4+
5+
```wit
6+
interface "wasi:sql" {
7+
// one single row item
8+
record row {
9+
field-name: string,
10+
value: data-type,
11+
}
12+
13+
// common data types
14+
variant data-type {
15+
int32(s32),
16+
int64(s64),
17+
uint32(u32),
18+
uint64(u64),
19+
float(float64),
20+
double(float64),
21+
str(string),
22+
boolean(bool),
23+
date(string),
24+
time(string),
25+
timestamp(string),
26+
binary(list<u8>),
27+
null
28+
}
29+
30+
// allows parameterized queries
31+
resource statement {
32+
// e.g., create("SELECT * FROM users WHERE name = ? AND age = ?", vec!["John Doe", "32"])
33+
prepare: func(query: string, params: list<string>) -> result<statement, sql-error>
34+
}
35+
36+
// query is optimized for querying data, and
37+
// implementors can make use of that fact to optimize
38+
// the performance of query execution (e.g., using
39+
// indexes).
40+
query: func(q: statement) -> result<list<row>, sql-error>
41+
42+
// exec is for modifying data in the database.
43+
exec: func(q: statement) -> result<_, sql-error>
44+
45+
// common error types
46+
variant sql-error {
47+
syntax-error(string),
48+
constraint-violation(string),
49+
access-violation(string),
50+
unexpected-error(string)
51+
}
52+
}
53+
```
54+
55+
## Worlds
56+
57+
```wit
58+
world "wasi:sql/http-sql" {
59+
import sql: "wasi:sql"
60+
61+
export handle-create: "wasi:http/handler"
62+
export handle-read: "wasi:http/handler"
63+
export handle-update: "wasi:http/handler"
64+
export handle-delete: "wasi:http/handler"
65+
}
66+
```

0 commit comments

Comments
 (0)