2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PostgreSQLのマネージドサービス xataを使ってみた

Last updated at Posted at 2024-08-23

xata とは?

PostgreSQL のマネージドサービスです。
Google アカウントまたは Github アカウントを使用してログインできます。
現状、無料でサービスを利用することもできます。

似たようなサービスに supabase , neon, tembo 等 があります。
無料枠という観点では、xata は使用できるストレージサイズが大きいです。

■ 無料枠

機能 supabase neon tembo xata
メモリ 500MB 1GB 1GB ?
ストレージ 1GB 0.5GB 10GB 15GB(+検索エンジン 15GB)
ベンダーサポート なし(有志) なし(有志) あり なし(有志)
拡張機能 ? あり あり なし
ダッシュボード なし ? あり なし

■ 利用方法

Database name を入力して Next を押します
1

Credentials をダウンロードして、Continue を押します
2

接続方法を選択します
3

接続方法が紹介されているページが表示されるので、この通りにコマンドを実行します
5

CLI をインストールします

C:\Users\masami>npm install @xata.io/cli -g

added 383 packages in 1m

135 packages are looking for funding
  run `npm fund` for details
npm notice
npm notice New minor version of npm available! 10.2.4 -> 10.8.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.2
npm notice Run npm install -g npm@10.8.2 to update!
npm notice

認証します

C:\Users\masami>xata auth login
√ Do you want to use an existing API key or create a new API key? » Use an existing API key
√ Existing API key: ... *************************************
i Checking access to the API...
✔ All set! you can now start using xata

プロジェクトのセットアップします

C:\Users\masami>xata init --db https://pea-sys-s-workspace-pnvaao.us-east-1.xata.sh/db/sample
🦋 Initializing project... We will ask you some questions.

√ Create .gitignore and ignore .env? ... yes
√ Generate code and types from your Xata database » TypeScript
√ Choose the output path for the generated code ... src/xata.ts

Setting up Xata...

Created Xata config: .xatarc

Creating .env file
  set XATA_API_KEY=xau_*********************************
  set XATA_BRANCH=main

Added .env file to .gitignore

i Running npm install --save @xata.io/client

added 2 packages, and audited 11 packages in 3s

found 0 vulnerabilities

No new migrations to pull from main branch
Generated Xata code to ./src\xata.ts

✔ Project setup with Xata 🦋

i Setup tables and columns at https://app.xata.io/workspaces/pea-sys-s-workspace-pnvaao/dbs/sample:us-east-1

i Use xata pull main to regenerate code and types from your Xata database

<XATA_API_KEY>を Credentials ページでダウンロードした API_KEY に書き換えてクエリを投げます

curl.exe --request GET --url "https://pea-sys-s-workspace-pnvaao.us-east-1.xata.sh/db/sample:main/tables/tableName/data/rec_xyz" --header "Authorization: Bearer <XATA_API_KEY>" --header "Content-Type:
application/json"
{"id":"27169203-012f-9247-a9c8-d4c6c3a2d2ed","message":"table [sample:main/tableName] not found"}

クエリの実行結果が取得できています

Credentials ページで Finish ボタンを押すと、プロジェクトページに遷移します
5

中央の Start with sample data を押します
データが作成されると、テーブルが表示されます
6

右上の Get code snippet をクリックし、Get one record のスニペットをコピーします

7

rec_xyz の部分を実際に存在するレコードの ID データに書き換えます。

curl.exe --request GET --url "https://pea-sys-s-workspace-pnvaao.us-east-1.xata.sh/db/sample:main/tables/tag/data/aiden" --header "Authorization: Bearer <XATA_API_KEY>" --header "Content-Type: applicat
ion/json"
{"id":"aiden","name":"vobis suppellex turpis 🎨 adsidue approbo ambitus soleo tactus cogo vulgivagus thorax vitium vulgivagus ubi 🦜 at amissio vigilo cohibeo","xata":{"createdAt":"2024-08-23T22:20:48.979157Z","updatedAt":"2024-08-23T22:20:48.979157Z","version":0}}

ブラウザからクエリも実行できます。
現状、EXPLAIN 等の一部クエリがサポートされていません。

8

クエリの制限を独自インターフェースによって狭められるてしまうので、個人的に psql から生クエリを実行したいところですが、今のところ Beta 版のようです。

アカウントトップページのSettingsからDelete workspaceを実行することでワークスペースを削除できます。
7

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?