await db.createTable("risk", "int", 25);await db.createTable("weather", "enum", 18, { isTemporal: true, constraints: { kind: { case: "enumConstraint", value: { choices: ["晴れ", "曇り", "雨"] } } } as never,});
const risk = db.table<number>("risk"); // 書く値と読んだ値の型(サーバーの定義とは連動しない)
await db.listTables();await table.info();await table.delete();await client.tableClient.update({ dbName, tableName, newName }); // 改名await table.insert(80, id); // 上書きawait table.upsert(80, id); // 空いている部分だけawait table.remove(id);await table.insert(80, [id1, id2]); // 同じ値をまとめてawait table.insert(80, id, "normalize"); // 細かすぎる ID を親に丸める("error" / "ignore")const results = await table.search(area).toArray();for await (const { id, value } of table.search(area, { format: "singleId" })) { /* ... */ }
// テーブル全体await table.search(RangeId.create(0, [-1, 0], 0, 0)).toArray();table.info() の count は、テーブル全体を format: "flexId" で検索した件数と一致します。
await weather.insert("晴れ", place.withTime(3600, t));await weather.search(place.withTime(Interval.DAY, day)).toArray(); // その日に含まれるデータ座標との変換
Section titled “座標との変換”const id = Coordinate.create(35.6812, 139.7671, 10).toSingleId(20); // 緯度・経度(度)・高度(m)→ 20/0/931389/412906id.toCenterCoordinate(); // 中心の座標id.toCoordinateRange(); // { latitude: [南端, 北端], longitude: [西端, 東端], altitude: [下端, 上端] }緯度は ±85.0511 度、経度は ±180 度、高度は ±225 m の範囲で渡します。範囲外は GeometryError になります。
const q = query.source("city", "risk").filter({ min: 50 }).zoomOut(20, "max");const results = await client.query(q, area, { format: "singleId" }).toArray();try { await table.insert(80, id);} catch (e) { if (isNotFoundError(e)) { /* テーブルが無い */ } else if (isKasaneError(e)) console.error(e.message); // "[invalid_argument] ..."}サーバーのエラーは、e.message の先頭の [ ] 内が種類です。
| 種類 | 主な原因 | 判定する関数 |
|---|---|---|
invalid_argument |
型の不一致、制約違反、ズームレベルの上限超え、使えない時間間隔、policy の指定漏れ |
— |
not_found |
テーブルが無い | isNotFoundError(e) |
already_exists |
同名のテーブルがある | isAlreadyExistsError(e) |
permission_denied |
権限が無い | isPermissionDeniedError(e) |
unauthenticated |
ログインできていない | isUnauthenticatedError(e) |
unknown |
サーバーに接続できない(fetch failed、Unable to connect) |
— |
internal |
サーバー内部のエラー(Kasane の不具合の可能性) | — |
通信の前にクライアントが投げるエラーもあります。どちらも e.info.kind に原因が入ります。
| エラー | 発生する場面 | kind の例 |
|---|---|---|
SpatialIdError |
空間ID の値や書式が不正 | ZOutOfRange、XOutOfRange、TIntervalError、ParseSpatialIdFormat |
GeometryError |
緯度・経度・高度が範囲外 | LatitudeOutOfRange、LongitudeOutOfRange、AltitudeOutOfRange |