参考、出典などのリンク
- PlanetScaleというサーバレスDBが凄く勢いのあるサービスらしいのでQuick Startやってみ
- PlanetScale
- PlanetScale quick start guide
- PlanetScale CLI
やってみた、スタート
アクセス
GitHubでの登録とDB作成
DB名は、やっている途中で流していた、相対性理論のアルバム名から・・・
ブラウザ上でクエリを叩いてみる
mainブランチを本番用にして保護する
新しい開発用ブランチを作成して、DBに接続する
hogehoge@fugafugafuga develop % brew install planetscale/tap/pscale
==> Tapping planetscale/tap
Cloning into '/usr/local/Homebrew/Library/Taps/planetscale/homebrew-tap'...
remote: Enumerating objects: 504, done.
remote: Counting objects: 100% (504/504), done.
remote: Compressing objects: 100% (488/488), done.
remote: Total 504 (delta 162), reused 33 (delta 10), pack-reused 0
Receiving objects: 100% (504/504), 84.31 KiB | 2.28 MiB/s, done.
Resolving deltas: 100% (162/162), done.
Tapped 2 formulae (15 files, 106.5KB).
==> Downloading https://github.com/planetscale/cli/releases/download/v0.89.0/pscale_0.89.0_macOS_amd64.tar.gz
==> Downloading from https://objects.githubusercontent.com/github-production-release-asset-2e65be/317614271/05fc88b8-d84f-46ab-a10c-3498722e5314?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Cred
######################################################################## 100.0%
==> Installing pscale from planetscale/tap
==> Caveats
zsh completions have been installed to:
/usr/local/share/zsh/site-functions
==> Summary
🍺 /usr/local/Cellar/pscale/0.89.0: 8 files, 10.2MB, built in 4 seconds
==> Running `brew cleanup pscale`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
hogehoge@fugafugafuga develop %
brew update, brew upgradeは事前にやっておきましょう・・・
hogehoge@fugafugafuga develop % pscale --version
pscale version 0.89.0 (build date: 2022-01-24T18:17:47Z commit: 6405542)
hogehoge@fugafugafuga develop %
hogehoge@fugafugafuga develop % pscale auth login
Confirmation Code: XXXXXXXX
If something goes wrong, copy and paste this URL into your browser: https://auth.planetscale.com/oauth/device?user_code=XXXXXXXX
Successfully logged in.
hogehoge@fugafugafuga develop %
Confirmation Codeがconsole上に表示されましたが、ブラウザ上で承認すれば問題なくログインできます。
hogehoge@fugafugafuga develop % pscale shell syncroniciteen dev1
Error: couldn't find the 'mysql' command-line tool required to run this command.
To install, run: brew install mysql-client
hogehoge@fugafugafuga develop %
hogehoge@fugafugafuga develop % brew install mysql-client
==> Downloading https://ghcr.io/v2/homebrew/core/libcbor/manifests/0.9.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libcbor/blobs/sha256:d07e3853a1d2d1cabe8ac3f4c005a3d90226f9f5faa8d174f61c76b121a351cc
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:d07e3853a1d2d1cabe8ac3f4c005a3d90226f9f5faa8d174f61c76b121a351cc?se=2022-03-20T01%3A40%3A00Z&sig=1SnOVN
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libfido2/manifests/1.10.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libfido2/blobs/sha256:61720be49bd0fdb87b7900122e22511514f87e0d5c73eb186664bfeee274f451
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:61720be49bd0fdb87b7900122e22511514f87e0d5c73eb186664bfeee274f451?se=2022-03-20T01%3A40%3A00Z&sig=SqLwiG
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/mysql-client/manifests/8.0.28
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/mysql-client/blobs/sha256:fc037da725fac5450fd5246b0ba2854c963ca90f1b1ebff34f111dc4bcc41a80
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:fc037da725fac5450fd5246b0ba2854c963ca90f1b1ebff34f111dc4bcc41a80?se=2022-03-20T01%3A40%3A00Z&sig=W6ee3G
######################################################################## 100.0%
==> Installing dependencies for mysql-client: libcbor and libfido2
==> Installing mysql-client dependency: libcbor
==> Pouring libcbor--0.9.0.monterey.bottle.tar.gz
🍺 /usr/local/Cellar/libcbor/0.9.0: 31 files, 161.7KB
==> Installing mysql-client dependency: libfido2
==> Pouring libfido2--1.10.0.monterey.bottle.tar.gz
🍺 /usr/local/Cellar/libfido2/1.10.0: 510 files, 1MB
==> Installing mysql-client
==> Pouring mysql-client--8.0.28.monterey.bottle.tar.gz
==> Caveats
mysql-client is keg-only, which means it was not symlinked into /usr/local,
because it conflicts with mysql (which contains client libraries).
If you need to have mysql-client first in your PATH, run:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
For compilers to find mysql-client you may need to set:
export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
export CPPFLAGS="-I/usr/local/opt/mysql-client/include"
For pkg-config to find mysql-client you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/mysql-client/lib/pkgconfig"
==> Summary
🍺 /usr/local/Cellar/mysql-client/8.0.28: 168 files, 154.2MB
==> Running `brew cleanup mysql-client`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> mysql-client
mysql-client is keg-only, which means it was not symlinked into /usr/local,
because it conflicts with mysql (which contains client libraries).
If you need to have mysql-client first in your PATH, run:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
For compilers to find mysql-client you may need to set:
export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
export CPPFLAGS="-I/usr/local/opt/mysql-client/include"
For pkg-config to find mysql-client you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/mysql-client/lib/pkgconfig"
hogehoge@fugafugafuga develop %
hogehoge@fugafugafuga develop %
hogehoge@fugafugafuga develop % pscale shell syncroniciteen dev1
syncroniciteen/dev1>
syncroniciteen/dev1> use users;
ERROR 1105 (HY000): unknown database 'users'
syncroniciteen/dev1>
syncroniciteen/dev1> select count(*) from users;
+----------+
| count(*) |
+----------+
| 0 |
+----------+
syncroniciteen/dev1> insert into `users` (id, email, first_name, last_name) values (1, 'fuga@test.com', 'ccccc', 'ddddd');
syncroniciteen/dev1> select count(*) from users;
+----------+
| count(*) |
+----------+
| 1 |
+----------+
syncroniciteen/dev1> select * from users;
+----+---------------+------------+-----------+
| id | email | first_name | last_name |
+----+---------------+------------+-----------+
| 1 | fuga@test.com | ccccc | ddddd |
+----+---------------+------------+-----------+
syncroniciteen/dev1>
syncroniciteen/dev1> commit;
syncroniciteen/dev1>
syncroniciteen/dev1> exit
hogehoge@fugafugafuga develop %
案の定mysqlがなかったので、インストールしてからリトライ。
hogehoge@fugafugafuga develop % git clone https://github.com/planetscale/express-example.git
Cloning into 'express-example'...
remote: Enumerating objects: 126, done.
remote: Counting objects: 100% (126/126), done.
remote: Compressing objects: 100% (92/92), done.
remote: Total 126 (delta 65), reused 78 (delta 32), pack-reused 0
Receiving objects: 100% (126/126), 13.31 MiB | 10.04 MiB/s, done.
Resolving deltas: 100% (65/65), done.
hogehoge@fugafugafuga develop %
hogehoge@fugafugafuga develop % ls
express-example
hogehoge@fugafugafuga develop %
hogehoge@fugafugafuga develop % cd express-example
hogehoge@fugafugafuga express-example %
hogehoge@fugafugafuga express-example % npm install
added 65 packages, and audited 66 packages in 2s
found 0 vulnerabilities
npm notice
npm notice New patch version of npm available! 8.5.2 -> 8.5.5
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.5.5
npm notice Run npm install -g npm@8.5.5 to update!
npm notice
hogehoge@fugafugafuga express-example %
git cloneした後、express-exampleに移動してからnpm installを叩くのを忘れずに。
hogehoge@fugafugafuga express-example % pscale connect syncroniciteen dev1 --execute 'node app.js'
Secure connection to database syncroniciteen and branch dev1 is established!.
Local address to connect your application: 127.0.0.1:3306 (press ctrl-c to quit)
Example app listening at http://localhost:3000
'note app.jp'と打ち込んだら、そりゃ立ち上がらない。
最後に
ローカルにDB置く必要もなく、自作アプリからも呼び出せるし、面白いなぁ。
入れるデータには気をつけなきゃいけないですが、色々と「あんなのこんなの」が想像できて、とても楽しいです。