You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -37,7 +39,11 @@ The exact detail of calling these operations from your application depends on yo
37
39
38
40
> [**Want to go straight to the reference documentation?** Find it here.](https://docs.rs/spin-sdk/latest/spin_sdk/index.html)
39
41
40
-
MySQL functions are available in the `spin_sdk::mysql` module, and PostgreSQL functions in the `spin_sdk::pg` module. The function names match the operations above. This example shows MySQL:
42
+
MySQL functions are available in the `spin_sdk::mysql` module, and PostgreSQL functions in the `spin_sdk::pg4` module.
43
+
44
+
> If you want to be compatible with Spin 3.3 or earlier, or with downstream hosts that have not yet rolled out Spin 3.4 support, you should use the `spin_sdk::pg3` module for PostgreSQL. The module interfaces are identical, but `pg3` does not support all the data types in `pg4`.
45
+
46
+
The function names match the operations above. This example shows MySQL:
41
47
42
48
```rust
43
49
// For PostgreSQL, use `spin_sdk::pg` or `spin_sdk::pg3`
@@ -207,6 +213,22 @@ func init() {
207
213
208
214
{{ blockEnd }}
209
215
216
+
## Application Development Considerations
217
+
218
+
This section contains notes and gotchas for developers using Spin's relational database APIs.
219
+
220
+
### PostgreSQL Range Queries
221
+
222
+
The PostgreSQL "range contains" operator, `<@`, is overloaded for "contains value" and "contains another range." This ambiguity can result in "wrong type" errors when executing "range contains" queries where the left hand side is parameterised.
223
+
224
+
To avoid this, use a type annotation on the parameter placeholder, e.g.:
225
+
226
+
```
227
+
SELECT name FROM cats WHERE $1::int4 <@ reign
228
+
```
229
+
230
+
The ambiguity is tracked at https://github.com/sfackler/rust-postgres/issues/1258.
231
+
210
232
## Granting Network Permissions to Components
211
233
212
234
By default, Spin components are not allowed to make outgoing network requests, including MySQL or PostgreSQL. This follows the general Wasm rule that modules must be explicitly granted capabilities, which is important to sandboxing. To grant a component permission to make network requests to a particular host, use the `allowed_outbound_hosts` field in the component manifest, specifying the host and allowed port:
Copy file name to clipboardExpand all lines: content/v3/sqlite-api-guide.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,8 @@ The set of operations is common across all SDKs:
37
37
|------------|------------|---------|----------|
38
38
|`open`| name | connection | Open the database with the specified name. If `name` is the string "default", the default database is opened, provided that the component that was granted access in the component manifest from `spin.toml`. Otherwise, `name` must refer to a store defined and configured in a [runtime configuration file](./dynamic-configuration.md#sqlite-storage-runtime-configuration) supplied with the application.|
39
39
|`execute`| connection, sql, parameters | database records | Executes the SQL statement and returns the results of the statement. SELECT statements typically return records or scalars. INSERT, UPDATE, and DELETE statements typically return empty result sets, but may return values in some cases. The `execute` operation recognizes the [SQLite dialect of SQL](https://www.sqlite.org/lang.html). |
40
+
|`last-insert-rowid`| connection | integer | The SQLite rowid of the recent successful INSERT on the connection, or 0 if there has not yet been an INSERT on the connection. |
41
+
|`changes`| connection | integer | The number of rows modified, inserted or deleted by the most recently completed INSERT, UPDATE or DELETE statement on the connection. |
40
42
41
43
The exact detail of calling these operations from your application depends on your language:
> [**Want to go straight to the reference documentation?** Find it here.](https://docs.rs/spin-sdk/latest/spin_sdk/sqlite/index.html)
57
+
> [**Want to go straight to the reference documentation?** Find it here.](https://docs.rs/spin-sdk/latest/spin_sdk/sqlite3/index.html)
56
58
57
-
SQLite functions are available in the `spin_sdk::sqlite` module. The function names match the operations above. For example:
59
+
SQLite functions are available in the `spin_sdk::sqlite3` module
60
+
61
+
> If you want to be compatible with Spin 3.1 or earlier, or with downstream hosts that have not yet rolled out Spin 3.2 support, you should use the `spin_sdk::sqlite` module for PostgreSQL. The only difference is that `sqlite` doesn't provide the `Connection::last_insert_rowid` and `Connection::changes` functions.
62
+
63
+
The function names match the operations above. For example:
0 commit comments