File
Blob: src/cloudflare/internal/test/d1/d1-api-test.py
| 1 | # Copyright (c) 2023 Cloudflare, Inc. |
| 2 | # Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | # https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | |
| 6 | def assertSuccess(ret): |
| 7 | # D1 operations return an object with a `success` field. |
| 8 | assert ret.success |
| 9 | |
| 10 | |
| 11 | async def test(context, env): |
| 12 | DB = env.d1 |
| 13 | |
| 14 | assertSuccess( |
| 15 | await DB.prepare( |
| 16 | """CREATE TABLE users |
| 17 | ( |
| 18 | user_id INTEGER PRIMARY KEY, |
| 19 | name TEXT, |
| 20 | home TEXT, |
| 21 | features TEXT, |
| 22 | land_based BOOLEAN |
| 23 | ); |
| 24 | """ |
| 25 | ).run() |
| 26 | ) |
| 27 | |
| 28 | result = await DB.prepare( |
| 29 | """ |
| 30 | INSERT INTO users (name, home, features, land_based) VALUES |
| 31 | ('Albert Ross', 'sky', 'wingspan', false), |
| 32 | ('Al Dente', 'bowl', 'mouthfeel', true) |
| 33 | RETURNING * |
| 34 | """ |
| 35 | ).all() |
| 36 | |
| 37 | assertSuccess(result) |
| 38 | assert len(result.results) == 2 |
| 39 | assert result.results[0].name == "Albert Ross" |