Upgrade to Pro — share decks privately, control downloads, hide ads and more …

テテミート 2024.11.22

Avatar for o-ga o-ga
November 22, 2024
10

テテミート 2024.11.22

Avatar for o-ga

o-ga

November 22, 2024
Tweet

Transcript

  1. 目次 📝 対象者 sqlcとは? typedSQLとは? sqlc vs TypedSQL 使用可能な言語 使用例

    - 基礎編 使用例 - 応用編 所感 まとめ さいごに 6
  2. sqlc - GitHub sqlc generates type-safe code from SQL. Here's

    how it works: 1. You write queries in SQL. 2. You run sqlc to generate code with type-safe interfaces to those queries. 3. You write application code that calls the generated code. Check out an interactive example to see it in action, and the introductory blog post for the motivation behind sqlc. 簡単にいうと、 sqlcは、型安全なコードを生成します 🎉 そのために、プログラマーは、 1. SQLを書く 2. sqlcコマンドでコードを生成する 3. アプケーションコードからsqlcで生成されたコードを呼び出す 9
  3. point 1. 手軽さ sqlc 設定ファイルのyaml + DDL + SQL で

    sqlc generate TypedSQL schema.prisma ファイルにTypedSQLを使用する設定を書いて、 sql/ 配下 に .sql にクエリを書く マイグレショーションは、prismaを使用する場合と同じく schema.prisma に定義 を書く Model 定義が独自記法 🎉 Winner 🎉 - sqlc 13
  4. 使ってみる 🎉 - Typescript getAuthor(dbconnection, { id: 1 }) が生成されたメソッド

    dbコネクションと、生成さ れた型定義で引数を渡す 23
  5. 試すSQL SELECT users.id AS user_id, users.name AS user_name, COUNT(items.id) AS

    item_count FROM items JOIN users ON items.user_id = users.id WHERE items.created_at BETWEEN '開始日' AND '終了日' GROUP BY users.id, users.name ORDER BY item_count DESC; 31