Open10
tbls-ask を動かすまで

これを動かしたい

go はほとんど使ったことがないので探り探り

make build
で実行ファイルを作れるところまではわかったが、ビルド時にこのようなエラーになった
# github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud
compile: version "go1.21.0" does not match go tool version "go1.21.7"

どうやら go の version が違うらしい

go の version 自体は良かったのだが、どうやら goenv
と競合してよくわからないことになっている模様
% go version
go version go1.21.7 darwin/arm64

以下の記事を参考にして goenv を uninstall して解決

ビルドは成功、だがその先どうやったらいいのかわからない

OPENAI_API_KEY
と TBLS_SCEMA
という環境変数を設定したら動いた
% envchain personal go run . count blog posts per user
To count the number of blog posts per user, you can use a `GROUP BY` clause in a SQL query, aggregating the number of posts for each user. In the WordPress database schema, the `wp_posts` table contains the blog posts, and the `post_author` column references the `ID` of the user in the `wp_users` table who authored the post.
Here is the SQL query that counts the number of blog posts per user:
SELECT
p.post_author,
u.user_login,
COUNT(*) AS post_count
FROM
wp_posts p
JOIN
wp_users u ON p.post_author = u.ID
WHERE
p.post_type = 'post' -- Only select blog posts, not pages or custom post types
AND p.post_status = 'publish' -- Only count published posts
GROUP BY
p.post_author
ORDER BY
post_count DESC;
This query will give you a list of users along with the number of published blog posts they have authored. The `WHERE` clause ensures that only blog posts (`post_type = 'post'`) that are published (`post_status = 'publish'`) are counted. The `GROUP BY` clause groups the results by the `post_author` field, and the `COUNT(*)` function counts the number of posts for each author. The `JOIN` clause is used to include the `user_login` from the `wp_users` table to display the user's login name alongside their post count.
Please note that the query assumes that you are interested in counting only published blog posts. If you want to include posts with other statuses (e.g., draft, pending), you would need to adjust the `WHERE` clause accordingly.

ちなみに TBLS_SCHEMA
の内容はこんな感じ
テストでついてくる json をそのまま使った
% echo $TBLS_SCHEMA
./testdata/wordpress.json

それにしてもこれは夢があるなぁ