Skip to content

Commit fd9aa22

Browse files
Mossakadanbugs
andauthored
chore(*): refresh WIT syntax (#7)
* chore(*): refresh WIT syntax This commit refreshes the WIT syntax defined in the existing interfaces to the newest syntax. It also changes `//` to `///` and generates a markdown file for documentation. Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> * Update wit/types.wit Co-authored-by: Dan Chiarlone <[email protected]> --------- Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]> Co-authored-by: Dan Chiarlone <[email protected]>
1 parent 2d2731c commit fd9aa22

File tree

5 files changed

+145
-156
lines changed

5 files changed

+145
-156
lines changed

imports.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<h1><a name="imports">World imports</a></h1>
2+
<ul>
3+
<li>Imports:
4+
<ul>
5+
<li>interface <a href="#wasi:sql_types_0.1.0"><code>wasi:sql/[email protected]</code></a></li>
6+
<li>interface <a href="#wasi:sql_readwrite_0.1.0"><code>wasi:sql/[email protected]</code></a></li>
7+
</ul>
8+
</li>
9+
</ul>
10+
<h2><a name="wasi:sql_types_0.1.0">Import interface wasi:sql/[email protected]</a></h2>
11+
<hr />
12+
<h3>Types</h3>
13+
<h4><a name="data_type"><code>variant data-type</code></a></h4>
14+
<p>common data types</p>
15+
<h5>Variant Cases</h5>
16+
<ul>
17+
<li><a name="data_type.int32"><code>int32</code></a>: <code>s32</code></li>
18+
<li><a name="data_type.int64"><code>int64</code></a>: <code>s64</code></li>
19+
<li><a name="data_type.uint32"><code>uint32</code></a>: <code>u32</code></li>
20+
<li><a name="data_type.uint64"><code>uint64</code></a>: <code>u64</code></li>
21+
<li><a name="data_type.float"><code>float</code></a>: <code>float64</code></li>
22+
<li><a name="data_type.double"><code>double</code></a>: <code>float64</code></li>
23+
<li><a name="data_type.str"><code>str</code></a>: <code>string</code></li>
24+
<li><a name="data_type.boolean"><code>boolean</code></a>: <code>bool</code></li>
25+
<li><a name="data_type.date"><code>date</code></a>: <code>string</code></li>
26+
<li><a name="data_type.time"><code>time</code></a>: <code>string</code></li>
27+
<li><a name="data_type.timestamp"><code>timestamp</code></a>: <code>string</code></li>
28+
<li><a name="data_type.binary"><code>binary</code></a>: list&lt;<code>u8</code>&gt;</li>
29+
<li><a name="data_type.null"><code>null</code></a></li>
30+
</ul>
31+
<h4><a name="row"><code>record row</code></a></h4>
32+
<p>one single row item</p>
33+
<h5>Record Fields</h5>
34+
<ul>
35+
<li><a name="row.field_name"><code>field-name</code></a>: <code>string</code></li>
36+
<li><a name="row.value"><code>value</code></a>: <a href="#data_type"><a href="#data_type"><code>data-type</code></a></a></li>
37+
</ul>
38+
<h4><a name="statement"><code>resource statement</code></a></h4>
39+
<p>allows parameterized queries
40+
e.g., prepare(&quot;SELECT * FROM users WHERE name = ? AND age = ?&quot;, vec![&quot;John Doe&quot;, &quot;32&quot;])</p>
41+
<h4><a name="error"><code>resource error</code></a></h4>
42+
<p>An error resource type.
43+
Currently, this provides only one function to return a string representation
44+
of the error. In the future, this will be extended to provide more information.</p>
45+
<h4><a name="connection"><code>resource connection</code></a></h4>
46+
<h2>A connection to a sql store.</h2>
47+
<h3>Functions</h3>
48+
<h4><a name="static_statement.prepare"><code>[static]statement.prepare: func</code></a></h4>
49+
<h5>Params</h5>
50+
<ul>
51+
<li><a name="static_statement.prepare.query"><a href="#query"><code>query</code></a></a>: <code>string</code></li>
52+
<li><a name="static_statement.prepare.params"><code>params</code></a>: list&lt;<code>string</code>&gt;</li>
53+
</ul>
54+
<h5>Return values</h5>
55+
<ul>
56+
<li><a name="static_statement.prepare.0"></a> result&lt;own&lt;<a href="#statement"><a href="#statement"><code>statement</code></a></a>&gt;, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
57+
</ul>
58+
<h4><a name="method_error.trace"><code>[method]error.trace: func</code></a></h4>
59+
<h5>Params</h5>
60+
<ul>
61+
<li><a name="method_error.trace.self"><code>self</code></a>: borrow&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
62+
</ul>
63+
<h5>Return values</h5>
64+
<ul>
65+
<li><a name="method_error.trace.0"></a> <code>string</code></li>
66+
</ul>
67+
<h4><a name="static_connection.open"><code>[static]connection.open: func</code></a></h4>
68+
<h5>Params</h5>
69+
<ul>
70+
<li><a name="static_connection.open.name"><code>name</code></a>: <code>string</code></li>
71+
</ul>
72+
<h5>Return values</h5>
73+
<ul>
74+
<li><a name="static_connection.open.0"></a> result&lt;own&lt;<a href="#connection"><a href="#connection"><code>connection</code></a></a>&gt;, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
75+
</ul>
76+
<h2><a name="wasi:sql_readwrite_0.1.0">Import interface wasi:sql/[email protected]</a></h2>
77+
<hr />
78+
<h3>Types</h3>
79+
<h4><a name="statement"><code>type statement</code></a></h4>
80+
<p><a href="#statement"><a href="#statement"><code>statement</code></a></a></p>
81+
<p>
82+
#### <a name="row">`type row`</a>
83+
[`row`](#row)
84+
<p>
85+
#### <a name="error">`type error`</a>
86+
[`error`](#error)
87+
<p>
88+
#### <a name="connection">`type connection`</a>
89+
[`connection`](#connection)
90+
<p>
91+
----
92+
<h3>Functions</h3>
93+
<h4><a name="query"><code>query: func</code></a></h4>
94+
<p>query is optimized for querying data, and
95+
implementors can make use of that fact to optimize
96+
the performance of query execution (e.g., using
97+
indexes).</p>
98+
<h5>Params</h5>
99+
<ul>
100+
<li><a name="query.c"><code>c</code></a>: borrow&lt;<a href="#connection"><a href="#connection"><code>connection</code></a></a>&gt;</li>
101+
<li><a name="query.q"><code>q</code></a>: borrow&lt;<a href="#statement"><a href="#statement"><code>statement</code></a></a>&gt;</li>
102+
</ul>
103+
<h5>Return values</h5>
104+
<ul>
105+
<li><a name="query.0"></a> result&lt;list&lt;<a href="#row"><a href="#row"><code>row</code></a></a>&gt;, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
106+
</ul>
107+
<h4><a name="exec"><code>exec: func</code></a></h4>
108+
<p>exec is for modifying data in the database.</p>
109+
<h5>Params</h5>
110+
<ul>
111+
<li><a name="exec.c"><code>c</code></a>: borrow&lt;<a href="#connection"><a href="#connection"><code>connection</code></a></a>&gt;</li>
112+
<li><a name="exec.q"><code>q</code></a>: borrow&lt;<a href="#statement"><a href="#statement"><code>statement</code></a></a>&gt;</li>
113+
</ul>
114+
<h5>Return values</h5>
115+
<ul>
116+
<li><a name="exec.0"></a> result&lt;<code>u32</code>, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
117+
</ul>

wit/deps/io/streams.wit

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

wit/readwrite.wit

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
default interface readwrite {
2-
use pkg.types.{statement, row, error, connection}
1+
interface readwrite {
2+
use types.{statement, row, error, connection};
33

4-
// query is optimized for querying data, and
5-
// implementors can make use of that fact to optimize
6-
// the performance of query execution (e.g., using
7-
// indexes).
8-
query: func(c: connection, q: statement) -> result<list<row>, error>
4+
/// query is optimized for querying data, and
5+
/// implementors can make use of that fact to optimize
6+
/// the performance of query execution (e.g., using
7+
/// indexes).
8+
query: func(c: borrow<connection>, q: borrow<statement>) -> result<list<row>, error>;
99

10-
// exec is for modifying data in the database.
11-
exec: func(c: connection, q: statement) -> result<u32, error>
10+
/// exec is for modifying data in the database.
11+
exec: func(c: borrow<connection>, q: borrow<statement>) -> result<u32, error>;
1212
}

wit/sql.wit

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
default world sql {
2-
import readwrite: pkg.readwrite
1+
package wasi:sql@0.1.0;
2+
3+
world imports {
4+
import readwrite;
35
}

wit/types.wit

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
default interface types {
2-
// one single row item
1+
interface types {
2+
/// one single row item
33
record row {
44
field-name: string,
55
value: data-type,
66
}
77

8-
// common data types
8+
/// common data types
99
variant data-type {
1010
int32(s32),
1111
int64(s64),
@@ -22,22 +22,20 @@ default interface types {
2222
null
2323
}
2424

25-
// allows parameterized queries
26-
// e.g., prepare-statement("SELECT * FROM users WHERE name = ? AND age = ?", vec!["John Doe", "32"])
27-
type statement = u32
28-
drop-statement: func(s: statement)
29-
prepare-statement: func(query: string, params: list<string>) -> result<statement, error>
30-
25+
/// allows parameterized queries
26+
/// e.g., prepare("SELECT * FROM users WHERE name = ? AND age = ?", vec!["John Doe", "32"])
27+
resource statement {
28+
prepare: static func(query: string, params: list<string>) -> result<statement, error>;
29+
}
3130
/// An error resource type.
3231
/// Currently, this provides only one function to return a string representation
3332
/// of the error. In the future, this will be extended to provide more information.
34-
// TODO: switch to `resource error { ... }`
35-
type error = u32
36-
drop-error: func(e: error)
37-
trace-error: func(e: error) -> string
38-
33+
resource error {
34+
trace: func() -> string;
35+
}
36+
3937
/// A connection to a sql store.
40-
type connection = u32
41-
drop-connection: func(b: connection)
42-
open-connection: func(name: string) -> result<connection, error>
38+
resource connection {
39+
open: static func(name: string) -> result<connection, error>;
40+
}
4341
}

0 commit comments

Comments
 (0)