├── .github └── workflows │ └── main.yml ├── .gitignore ├── README.md ├── imports.md └── wit ├── readwrite.wit ├── sql.wit └── types.wit /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: [main] 5 | pull_request: 6 | branches: [main] 7 | 8 | jobs: 9 | abi-up-to-date: 10 | name: Check ABI files are up-to-date 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | - uses: WebAssembly/wit-abi-up-to-date@v17 15 | with: 16 | wit-bindgen: '0.18.0' 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WebAssembly/wasi-sql/d14174a2a03da5cb0985e662d9d0193afe1fae17/.gitignore -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `wasi-sql` 2 | 3 | A proposed [WebAssembly System Interface](https://github.com/WebAssembly/WASI) API. 4 | 5 | ### Current Phase 6 | 7 | `wasi-sql` is currently in [Phase 1](https://github.com/WebAssembly/WASI/blob/main/Proposals.md#phase-1---feature-proposal-cg). 8 | 9 | ### Champions 10 | 11 | - [Dan Chiarlone](https://github.com/danbugs) 12 | - [David Justice](https://github.com/devigned) 13 | - [Jiaxiao Zhou](https://github.com/Mossaka) 14 | 15 | ### Phase 4 Advancement Criteria 16 | 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. 18 | 19 | ## Table of Contents 20 | 21 | - [Introduction](#introduction) 22 | - [Goals [or Motivating Use Cases, or Scenarios]](#goals-or-motivating-use-cases-or-scenarios) 23 | - [Non-goals](#non-goals) 24 | 25 | ### Introduction 26 | 27 | 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. 28 | 29 | ### Goals 30 | 31 | 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. 32 | 33 | 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. 34 | 35 | ### Non-goals 36 | 37 | - 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. 38 | - 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. 39 | - 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. 40 | 41 | ### API walk-through 42 | 43 | For a full API walk-through, see [wasi-sql-demo](https://github.com/danbugs/wasi-sql-demo). 44 | 45 | > Note: This README needs to be expanded to cover a number of additional fields suggested in the 46 | [WASI Proposal template](https://github.com/WebAssembly/wasi-proposal-template). 47 | -------------------------------------------------------------------------------- /imports.md: -------------------------------------------------------------------------------- 1 |

World imports

2 | 10 |

Import interface wasi:sql/types@0.2.0-draft

11 |
12 |

Types

13 |

variant data-type

14 |

common data types

15 |
Variant Cases
16 | 31 |

record row

32 |

one single row item

33 |
Record Fields
34 | 38 |

resource statement

39 |

allows parameterized queries 40 | e.g., prepare("SELECT * FROM users WHERE name = ? AND age = ?", vec!["John Doe", "32"])

41 |

resource error

42 |

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.

45 |

resource connection

46 |

A connection to a sql store.

47 |

Functions

48 |

[static]statement.prepare: func

49 |
Params
50 | 54 |
Return values
55 | 58 |

[method]error.trace: func

59 |
Params
60 | 63 |
Return values
64 | 67 |

[static]connection.open: func

68 |
Params
69 | 72 |
Return values
73 | 76 |

Import interface wasi:sql/readwrite@0.2.0-draft

77 |
78 |

Types

79 |

type statement

80 |

statement

81 |

82 | #### `type row` 83 | [`row`](#row) 84 |

85 | #### `type error` 86 | [`error`](#error) 87 |

88 | #### `type connection` 89 | [`connection`](#connection) 90 |

91 | ---- 92 |

Functions

93 |

query: func

94 |

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).

98 |
Params
99 | 103 |
Return values
104 | 107 |

exec: func

108 |

exec is for modifying data in the database.

109 |
Params
110 | 114 |
Return values
115 | 118 | -------------------------------------------------------------------------------- /wit/readwrite.wit: -------------------------------------------------------------------------------- 1 | interface readwrite { 2 | use types.{statement, row, error, connection}; 3 | 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, q: borrow) -> result, error>; 9 | 10 | /// exec is for modifying data in the database. 11 | exec: func(c: borrow, q: borrow) -> result; 12 | } -------------------------------------------------------------------------------- /wit/sql.wit: -------------------------------------------------------------------------------- 1 | package wasi:sql@0.2.0-draft; 2 | 3 | world imports { 4 | import readwrite; 5 | } -------------------------------------------------------------------------------- /wit/types.wit: -------------------------------------------------------------------------------- 1 | interface types { 2 | /// one single row item 3 | record row { 4 | field-name: string, 5 | value: data-type, 6 | } 7 | 8 | /// common data types 9 | variant data-type { 10 | int32(s32), 11 | int64(s64), 12 | uint32(u32), 13 | uint64(u64), 14 | float(float64), 15 | double(float64), 16 | str(string), 17 | boolean(bool), 18 | date(string), 19 | time(string), 20 | timestamp(string), 21 | binary(list), 22 | null 23 | } 24 | 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) -> result; 29 | } 30 | /// An error resource type. 31 | /// Currently, this provides only one function to return a string representation 32 | /// of the error. In the future, this will be extended to provide more information. 33 | resource error { 34 | trace: func() -> string; 35 | } 36 | 37 | /// A connection to a sql store. 38 | resource connection { 39 | open: static func(name: string) -> result; 40 | } 41 | } --------------------------------------------------------------------------------