Open1

Tauri Rust , Postgres 使用メモ

knaka Tech-Blogknaka Tech-Blog

概要

  • Tauri Rust + Postgres メモになります

[ 公開 2025/10/06 ]


環境

  • Tauri windows ver
  • postgres Database
  • rustc 1.90.0
  • cargo 1.90.0
  • node 22 (テスト)

書いたコード

https://github.com/kuc-arc-f/tauri_2ex/tree/main/tauri-pg


  • tauri-pg/src-tauri/src/main.rs
  • CRUD 一部追加

https://github.com/kuc-arc-f/tauri_2ex/blob/main/tauri-pg/src-tauri/src/main.rs


  • tauri-pg/src-tauri/Cargo.toml

https://github.com/kuc-arc-f/tauri_2ex/blob/main/tauri-pg/src-tauri/Cargo.toml

[package]
name = "tauri-pg"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "tauri_pg_lib"
crate-type = ["staticlib", "cdylib", "rlib"]

[build-dependencies]
tauri-build = { version = "2", features = [] }

[dependencies]
anyhow = "1.0.100"
tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sqlx = { version = "0.7", features = ["runtime-tokio-rustls", "postgres", "macros", "chrono"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
chrono = { version = "0.4", features = ["serde"] }


  • tauri-pg/table.sql

https://github.com/kuc-arc-f/tauri_2ex/blob/main/tauri-pg/table.sql

create table todo(
  "id" SERIAL NOT NULL,
  data TEXT NOT NULL,
  created_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  CONSTRAINT "Todo_pkey" PRIMARY KEY ("id")
);


  • dev-start
npm run tauri dev
  • 登録の確認


  • react
  • tauri-pg/src/client/Todo.tsx

https://github.com/kuc-arc-f/tauri_2ex/blob/main/tauri-pg/src/client/Todo.tsx


  • 画面 react


  • build
npm run tauri build