| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | 
| rust:diesel [2024/05/22 05:53]  – [diesel]  ともやん | rust:diesel [2024/06/04 17:41] (現在)  – [データベース データ型との対応関係のヒント]  ともやん | 
|---|
| 本家: [[https://diesel.rs/|Diesel is a Safe, Extensible ORM and Query Builder for Rust]]\\ | 本家: [[https://diesel.rs/|Diesel is a Safe, Extensible ORM and Query Builder for Rust]]\\ | 
| ソースコード: [[git>diesel-rs/diesel|diesel-rs/diesel: A safe, extensible ORM and Query Builder for Rust]]\\ | ソースコード: [[git>diesel-rs/diesel|diesel-rs/diesel: A safe, extensible ORM and Query Builder for Rust]]\\ | 
|  | マイグレーションガイド: [[https://diesel.rs/guides/migration_guide.html|Diesel 2.0 migration guide]]\\ | 
| ===== インストール ===== | ===== インストール ===== | 
| 公式: [[https://diesel.rs/guides/getting-started|Getting Started with Diesel]]\\ | 公式: [[https://diesel.rs/guides/getting-started|Getting Started with Diesel]]\\ | 
|  |  | 
| ===== データベース ===== | ===== データベース ===== | 
| [[linux:podman:piwigo|Piwigo - オープンソースの写真管理 Web アプリ]] を使用する😅\\ | **PostgreSQL**\\ | 
|  | [[linux:podman:postgres|PostgreSQL]] (Podman)\\ | 
|  |  | 
|  | **MariaDB**\\ | 
|  | [[linux:podman:piwigo|Piwigo - オープンソースの写真管理 Web アプリ]] (Podman) を使用する😅\\ | 
|  |  | 
|  | **SQLite**\\ | 
|  | 構築の必要はない\\ | 
|  |  | 
| ===== ワークスペースの作成 ===== | ===== ワークスペースの作成 ===== | 
| </WRAP> | </WRAP> | 
|  |  | 
| ==== diesel ==== | ==== Diesel ==== | 
|  |  | 
| === データベース接続設定 === | === データベース接続設定 === | 
| 以下の mysql コマンドの仕様と同じ🤔\\ | 以下の mysql コマンドの仕様と同じ🤔\\ | 
| {{page>linux:mysql#unix_ドメインソケット経由の接続エラー&noheader}} | {{page>linux:mysql#unix_ドメインソケット経由の接続エラー&noheader}} | 
|  |  | 
|  | === RDBMS スキーマーから src/schema.rs を生成する === | 
|  | Diesel の print-schema コマンドでデータベース スキーマのテーブル定義を Rust ソースコードで出力できる🤔\\ | 
|  | <WRAP color_term> | 
|  | <WRAP color_command><html><pre> | 
|  | <font color="#0087FF"><b>$</b></font> <font color="#26A269">diesel</font> print-schema <font color="#A347BA">-o</font> piwigo_images <font color="#12488B"><b>|</b></font> <font color="#26A269">bat</font> <font color="#A347BA">-p</font> <font color="#A347BA">-l</font> rs <font color="#A347BA">--pager</font> never | 
|  | </pre></html></WRAP> | 
|  | <WRAP color_result_long><html><pre class=Bat> | 
|  | <font color="#75715E">// @generated automatically by Diesel CLI.</font> | 
|  |  | 
|  | <font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#66D9EF">mod</font><font color="#F8F8F2"> </font><font color="#A6E22E">sql_types</font><font color="#F8F8F2"> {</font> | 
|  | <font color="#F8F8F2">    #[derive(diesel::query_builder::QueryId, diesel::sql_types::SqlType)]</font> | 
|  | <font color="#F8F8F2">    #[diesel(mysql_type(name </font><font color="#F92672">=</font><font color="#F8F8F2"> </font><font color="#E6DB74">"Mediumint"</font><font color="#F8F8F2">))]</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#66D9EF">struct</font><font color="#F8F8F2"> </font><font color="#A6E22E">PiwigoImagesAddedByMediumint</font><font color="#F8F8F2">;</font> | 
|  |  | 
|  | <font color="#F8F8F2">    #[derive(diesel::query_builder::QueryId, diesel::sql_types::SqlType)]</font> | 
|  | <font color="#F8F8F2">    #[diesel(mysql_type(name </font><font color="#F92672">=</font><font color="#F8F8F2"> </font><font color="#E6DB74">"Mediumint"</font><font color="#F8F8F2">))]</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#66D9EF">struct</font><font color="#F8F8F2"> </font><font color="#A6E22E">PiwigoImagesFilesizeMediumint</font><font color="#F8F8F2">;</font> | 
|  |  | 
|  | <font color="#F8F8F2">    #[derive(diesel::query_builder::QueryId, diesel::sql_types::SqlType)]</font> | 
|  | <font color="#F8F8F2">    #[diesel(mysql_type(name </font><font color="#F92672">=</font><font color="#F8F8F2"> </font><font color="#E6DB74">"Mediumint"</font><font color="#F8F8F2">))]</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#66D9EF">struct</font><font color="#F8F8F2"> </font><font color="#A6E22E">PiwigoImagesIdMediumint</font><font color="#F8F8F2">;</font> | 
|  | <font color="#F8F8F2">}</font> | 
|  |  | 
|  | <font color="#F8F8F2">diesel::table</font><font color="#F92672">!</font><font color="#F8F8F2"> {</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">use</font><font color="#F8F8F2"> diesel::sql_types::</font><font color="#F92672">*</font><font color="#F8F8F2">;</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">use</font><font color="#F8F8F2"> </font><font color="#F92672">super</font><font color="#F8F8F2">::sql_types::PiwigoImagesIdMediumint;</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">use</font><font color="#F8F8F2"> </font><font color="#F92672">super</font><font color="#F8F8F2">::sql_types::PiwigoImagesFilesizeMediumint;</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">use</font><font color="#F8F8F2"> </font><font color="#F92672">super</font><font color="#F8F8F2">::sql_types::PiwigoImagesAddedByMediumint;</font> | 
|  |  | 
|  | <font color="#F8F8F2">    piwigo_images (id) {</font> | 
|  | <font color="#F8F8F2">        id -> Unsigned<PiwigoImagesIdMediumint>,</font> | 
|  | <font color="#F8F8F2">        #[max_length </font><font color="#F92672">=</font><font color="#F8F8F2"> 255]</font> | 
|  | <font color="#F8F8F2">        file -> Varchar,</font> | 
|  | <font color="#F8F8F2">        date_available -> Datetime,</font> | 
|  | <font color="#F8F8F2">        date_creation -> Nullable<Datetime>,</font> | 
|  | <font color="#F8F8F2">        #[max_length </font><font color="#F92672">=</font><font color="#F8F8F2"> 255]</font> | 
|  | <font color="#F8F8F2">        name -> Nullable<Varchar>,</font> | 
|  | <font color="#F8F8F2">        comment -> Nullable<Text>,</font> | 
|  | <font color="#F8F8F2">        #[max_length </font><font color="#F92672">=</font><font color="#F8F8F2"> 255]</font> | 
|  | <font color="#F8F8F2">        author -> Nullable<Varchar>,</font> | 
|  | <font color="#F8F8F2">        hit -> Unsigned<Integer>,</font> | 
|  | <font color="#F8F8F2">        filesize -> Nullable<Unsigned<PiwigoImagesFilesizeMediumint>>,</font> | 
|  | <font color="#F8F8F2">        width -> Nullable<Unsigned<Smallint>>,</font> | 
|  | <font color="#F8F8F2">        height -> Nullable<Unsigned<Smallint>>,</font> | 
|  | <font color="#F8F8F2">        #[max_length </font><font color="#F92672">=</font><font color="#F8F8F2"> 4]</font> | 
|  | <font color="#F8F8F2">        coi -> Nullable<Char>,</font> | 
|  | <font color="#F8F8F2">        #[max_length </font><font color="#F92672">=</font><font color="#F8F8F2"> 4]</font> | 
|  | <font color="#F8F8F2">        representative_ext -> Nullable<Varchar>,</font> | 
|  | <font color="#F8F8F2">        date_metadata_update -> Nullable<Date>,</font> | 
|  | <font color="#F8F8F2">        rating_score -> Nullable<Unsigned<Float>>,</font> | 
|  | <font color="#F8F8F2">        #[max_length </font><font color="#F92672">=</font><font color="#F8F8F2"> 255]</font> | 
|  | <font color="#F8F8F2">        path -> Varchar,</font> | 
|  | <font color="#F8F8F2">        storage_category_id -> Nullable<Unsigned<Smallint>>,</font> | 
|  | <font color="#F8F8F2">        level -> Unsigned<Tinyint>,</font> | 
|  | <font color="#F8F8F2">        #[max_length </font><font color="#F92672">=</font><font color="#F8F8F2"> 32]</font> | 
|  | <font color="#F8F8F2">        md5sum -> Nullable<Char>,</font> | 
|  | <font color="#F8F8F2">        added_by -> Unsigned<PiwigoImagesAddedByMediumint>,</font> | 
|  | <font color="#F8F8F2">        rotation -> Nullable<Unsigned<Tinyint>>,</font> | 
|  | <font color="#F8F8F2">        latitude -> Nullable<Double>,</font> | 
|  | <font color="#F8F8F2">        longitude -> Nullable<Double>,</font> | 
|  | <font color="#F8F8F2">        lastmodified -> Nullable<Timestamp>,</font> | 
|  | <font color="#F8F8F2">    }</font> | 
|  | <font color="#F8F8F2">}</font> | 
|  | </pre></html></WRAP> | 
|  | </WRAP> | 
|  | bat コマンドについては [[linux:bat|bat - シンタックスハイライトとGitとの連携機能付きの cat(1) クローン]] を参照😉\\ | 
|  |  | 
|  | それを <html><code>src/schema.rs</code></html> へリダイレクトで追記する😉\\ | 
|  | <WRAP color_term> | 
|  | <WRAP color_command><html><pre> | 
|  | <font color="#0087FF"><b>$</b></font> <font color="#26A269">diesel</font> print-schema <font color="#A347BA">-o</font> piwigo_images <font color="#12488B"><b>>></b></font> <u style="text-decoration-style:solid">src/schema.rs</u> | 
|  | </pre></html></WRAP> | 
|  | </WRAP> | 
|  |  | 
|  | === schema.rs から src/models.rs を生成する === | 
|  | <WRAP color_term> | 
|  | <WRAP color_command><html><pre> | 
|  | <font color="#0087FF"><b>$</b></font> <font color="#26A269">diesel_ext</font> <font color="#A347BA">--model</font> <font color="#A347BA">-t</font> <font color="#12488B"><b>|</b></font> <font color="#26A269">bat</font> <font color="#A347BA">-p</font> <font color="#A347BA">-l</font> rs <font color="#A347BA">--pager</font> never | 
|  | </pre></html></WRAP> | 
|  | <WRAP color_result_long><html><pre class=Bat> | 
|  | Unsigned<PiwigoImagesIdMediumint> is not recognized. Please feel free to expand the HashMap. This could provide good hints: <a href="https://kotiri.com/2018/01/31/postgresql-diesel-rust-types.html">https://kotiri.com/2018/01/31/postgresql-diesel-rust-types.html</a> | 
|  | Nullable<Unsigned<PiwigoImagesFilesizeMediumint>> is not recognized. Please feel free to expand the HashMap. This could provide good hints: <a href="https://kotiri.com/2018/01/31/postgresql-diesel-rust-types.html">https://kotiri.com/2018/01/31/postgresql-diesel-rust-types.html</a> | 
|  | Nullable<Unsigned<Float>> is not recognized. Please feel free to expand the HashMap. This could provide good hints: https://kotiri.com/2018/01/31/postgresql-diesel-rust-types.html | 
|  | Unsigned<PiwigoImagesAddedByMediumint> is not recognized. Please feel free to expand the HashMap. This could provide good hints: <a href="https://kotiri.com/2018/01/31/postgresql-diesel-rust-types.html">https://kotiri.com/2018/01/31/postgresql-diesel-rust-types.html</a> | 
|  | <font color="#75715E">// Generated by diesel_ext</font> | 
|  |  | 
|  | <font color="#F8F8F2">#![allow(unused)]</font> | 
|  | <font color="#F8F8F2">#![allow(clippy::all)]</font> | 
|  |  | 
|  |  | 
|  | <font color="#F92672">use</font><font color="#F8F8F2"> chrono::NaiveDate;</font> | 
|  | <font color="#F92672">use</font><font color="#F8F8F2"> chrono::NaiveDateTime;</font> | 
|  | <font color="#F8F8F2">#[derive(Queryable, Debug)]</font> | 
|  | <font color="#F8F8F2">#[diesel(table_name </font><font color="#F92672">=</font><font color="#F8F8F2"> piwigo_images)]</font> | 
|  | <font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#66D9EF">struct</font><font color="#F8F8F2"> </font><font color="#A6E22E">PiwigoImage</font><font color="#F8F8F2"> {</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">id</font><font color="#F8F8F2">: </font><font color="#75715E">/* TODO: unknown type Unsigned<PiwigoImagesIdMediumint> */</font><font color="#F8F8F2">,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">file</font><font color="#F8F8F2">: String,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">date_available</font><font color="#F8F8F2">: NaiveDateTime,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">date_creation</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><NaiveDateTime>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">name</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#A6E22E">String</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">comment</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#A6E22E">String</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">author</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#A6E22E">String</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">hit</font><font color="#F8F8F2">: </font><font color="#66D9EF">u32</font><font color="#F8F8F2">,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">filesize</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#75715E">/* TODO: unknown type Nullable<Unsigned<PiwigoImagesFilesizeMediumint>> */</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">width</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#66D9EF">u16</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">height</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#66D9EF">u16</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">coi</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#A6E22E">String</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">representative_ext</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#A6E22E">String</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">date_metadata_update</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><NaiveDate>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">rating_score</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#75715E">/* TODO: unknown type Nullable<Unsigned<Float>> */</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">path</font><font color="#F8F8F2">: String,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">storage_category_id</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#66D9EF">u16</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">level</font><font color="#F8F8F2">: </font><font color="#66D9EF">u8</font><font color="#F8F8F2">,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">md5sum</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#A6E22E">String</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">added_by</font><font color="#F8F8F2">: </font><font color="#75715E">/* TODO: unknown type Unsigned<PiwigoImagesAddedByMediumint> */</font><font color="#F8F8F2">,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">rotation</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#66D9EF">u8</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">latitude</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#66D9EF">f64</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">longitude</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><</font><font color="#66D9EF">f64</font><font color="#F8F8F2">>,</font> | 
|  | <font color="#F8F8F2">    </font><font color="#F92672">pub</font><font color="#F8F8F2"> </font><font color="#FFFFFF">lastmodified</font><font color="#F8F8F2">: </font><font color="#A6E22E">Option</font><font color="#F8F8F2"><NaiveDateTime>,</font> | 
|  | <font color="#F8F8F2">}</font> | 
|  |  | 
|  | </pre></html></WRAP> | 
|  | </WRAP> | 
|  |  | 
|  | === データベース データ型との対応関係のヒント === | 
|  | <html><script> | 
|  | function formatBigInt(bigint) { | 
|  | return bigint.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); | 
|  | } | 
|  | </script> | 
|  | <style> | 
|  | th { | 
|  | background-color: #eee; | 
|  | } | 
|  | .xtern_xtrn { | 
|  |  | 
|  | } | 
|  | </style></html> | 
|  | <WRAP mintbl minfont_12> | 
|  | 参考: [[https://dev.mysql.com/doc/refman/8.0/en/integer-types.html|MySQL :: MySQL 8.0 Reference Manual :: 13.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT]]\\ | 
|  | ^  タイプ ^  ストレージ (Bytes)  ^  符号付き最小値  ^  符号なしの最小値  ^  符号付き最大値  ^^  符号なしの最大値  ^^ | 
|  | |  TINYINT |  1 |  -128 |  0 |  127 | |  255 | | | 
|  | |  SMALLINT |  2 |  -32,768 |  0 |  32,767 | |  65,535 | | | 
|  | |  MEDIUMINT |  3 |  -8,388,608 |  0 |  8,388,607 | |  16,777,215 | | | 
|  | |  INT |  4 |  -2,147,483,648 |  0 |  2,147,483,647 | |  4,294,967,295 | | | 
|  | |  BIGINT |  8 |  -263 |  0 |  <html><script>document.write(formatBigInt(2n ** 63n -1n))</script></html> | 2<html><sup>63</sup></html>-1  |  <html><script>document.write(formatBigInt(2n ** 64n -1n))</script></html> | 2<html><sup>64</sup></html>-1  | | 
|  | </WRAP> | 
|  | <WRAP mintbl minfont_12> | 
|  | [[https://docs.diesel.rs/master/diesel/sql_types/|diesel::sql_types - Rust]]\\ | 
|  | [[https://docs.rs/min_max_traits/latest/min_max_traits/|min_max_traits - Rust]]\\ | 
|  | ^ 符号なし整数型  ^^^^^ | 
|  | ^  タイプ ^  最小値  ^^  最大値  ^^ | 
|  | |  u8 |  0 ||  <html><script>document.write(formatBigInt(2n ** 8n -1n))</script></html> | 2<html><sup>8</sup></html>-1  | | 
|  | |  u16 |  0 ||  <html><script>document.write(formatBigInt(2n ** 16n -1n))</script></html> | 2<html><sup>16</sup></html>-1  | | 
|  | |  u32 |  0 ||  <html><script>document.write(formatBigInt(2n ** 32n -1n))</script></html> | 2<html><sup>32</sup></html>-1  | | 
|  | |  u64 |  0 ||  <html><script>document.write(formatBigInt(2n ** 64n -1n))</script></html> | 2<html><sup>64</sup></html>-1  | | 
|  | |  u128 |  0 ||  <WRAP minfont9><html><script>document.write(formatBigInt(2n ** 128n -1n))</script></html></WRAP> | 2<html><sup>128</sup></html>-1  | | 
|  | ^ 符号付き 2 の補数整数型  ^^^^^ | 
|  | ^  タイプ ^  最小値  ^^  最大値  ^^ | 
|  | |  i8 |  <html><script>document.write(formatBigInt(-(2n ** 7n)))</script></html> | -(2<html><sup>7</sup></html>) |  <html><script>document.write(formatBigInt(2n ** 7n -1n))</script></html> | 2<html><sup>7</sup></html>-1 | | 
|  | |  i16 |  <html><script>document.write(formatBigInt(-(2n ** 15n)))</script></html> | -(2<html><sup>15</sup></html>) |  <html><script>document.write(formatBigInt(2n ** 15n -1n))</script></html> | 2<html><sup>15</sup></html>-1 | | 
|  | |  i32 |  <html><script>document.write(formatBigInt(-(2n ** 31n)))</script></html> | -(2<html><sup>31</sup></html>) |  <html><script>document.write(formatBigInt(2n ** 31n -1n))</script></html> | 2<html><sup>31</sup></html>-1 | | 
|  | |  i64 |  <html><script>document.write(formatBigInt(-(2n ** 63n)))</script></html> | -(2<html><sup>63</sup></html>) |  <html><script>document.write(formatBigInt(2n ** 63n -1n))</script></html> | 2<html><sup>63</sup></html>-1 | | 
|  | |  i128 |  <WRAP minfont9><html><script>document.write(formatBigInt(-(2n ** 127n)))</script></html></WRAP> | -(2<html><sup>127</sup></html>) |  <WRAP minfont9><html><script>document.write(formatBigInt(2n ** 127n -1n))</script></html></WRAP> | 2<html><sup>127</sup></html>-1 | | 
|  | </WRAP> | 
|  |  | 
|  | [[https://gist.github.com/steveh/7c7145409a5eed6b698ee8b609b6d1fc|postgresql-diesel-rust-types.md]]\\ | 
|  | <WRAP mintbl minfont_12> | 
|  | ^ PostgreSQL Type  ^ PostgreSQL Size  ^ Description  ^ Range  ^ Diesel Type  ^ Rust Type  ^ | 
|  | | Nullable Types  |  | nullable  |  | [[http://docs.diesel.rs/diesel/sql_types/struct.Nullable.html|Nullable]]<T>  | [[https://doc.rust-lang.org/std/option/enum.Option.html|Option]]<T>  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-numeric.html|Numeric Types]]  ^^^^^^ | 
|  | | smallint, int2  | 2 bytes  | signed integer  | -32768 to +32767  | [[http://docs.diesel.rs/diesel/sql_types/struct.SmallInt.html|SmallInt]]  | [[https://doc.rust-lang.org/std/primitive.i16.html|i16]]  | | 
|  | | integer, int, int4  | 4 bytes  | signed integer  | -2147483648 to +2147483647  | [[http://docs.diesel.rs/diesel/sql_types/struct.Integer.html|Integer]]  | [[https://doc.rust-lang.org/std/primitive.i32.html|i32]]  | | 
|  | | bigint, int8  | 8 bytes  | signed integer  | -9223372036854775808 to +9223372036854775807  | [[http://docs.diesel.rs/diesel/sql_types/struct.BigInt.html|BigInt]]  | [[https://doc.rust-lang.org/std/primitive.i64.html|i64]]  | | 
|  | | numeric(p, s), decimal(p, s)  | 2 bytes per 4 digits + 3 to 8 bytes  | exact numeric of selectable precision  | 131072.16383 digits  | [[http://docs.diesel.rs/diesel/sql_types/struct.Numeric.html|Numeric]]  | [[http://docs.diesel.rs/bigdecimal/struct.BigDecimal.html|bigdecimal::BigDecimal]]  | | 
|  | | real, float4  | 4 bytes  | single precision floating-point number | 6 digits precision  | [[http://docs.diesel.rs/diesel/sql_types/struct.Float.html|Float]]  | [[https://doc.rust-lang.org/std/primitive.f32.html|f32]]  | | 
|  | | double precision, float8  | 8 bytes  | double precision floating-point number | 15 digits precision  | [[http://docs.diesel.rs/diesel/sql_types/struct.Double.html|Double]]  | [[https://doc.rust-lang.org/std/primitive.f64.html|f64]]  | | 
|  | | smallserial, serial2  | 2 bytes  | autoincrementing integer  | 1 to 32767  | [[http://docs.diesel.rs/diesel/sql_types/struct.SmallInt.html|SmallInt]]  | [[https://doc.rust-lang.org/std/primitive.i16.html|i16]]  | | 
|  | | serial, serial4  | 4 bytes  | autoincrementing integer  | 1 to 2147483647  | [[http://docs.diesel.rs/diesel/sql_types/struct.Integer.html|Integer]]  | [[https://doc.rust-lang.org/std/primitive.i32.html|i32]]  | | 
|  | | bigserial, serial8  | 8 bytes  | autoincrementing integer  | 1 to 9223372036854775807  | [[http://docs.diesel.rs/diesel/sql_types/struct.BigInt.html|BigInt]]  | [[https://doc.rust-lang.org/std/primitive.i64.html|i64]]  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-money.html|Monetary Types]]  ^^^^^^ | 
|  | | money  | 8 bytes  | currency amount  | -92233720368547758.08 to +92233720368547758.07  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Money.html|Money]]  | [[http://docs.diesel.rs/diesel/pg/data_types/struct.Cents.html|Cents]]  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-character.html|Character Types]]  ^^^^^^ | 
|  | | character varying(n), varchar(n)  | n+1 or n+4 bytes  | variable-length character string  |  | [[http://docs.diesel.rs/diesel/sql_types/struct.Text.html|Text]]  | [[https://doc.rust-lang.org/std/string/struct.String.html|String]], &[[https://doc.rust-lang.org/std/primitive.str.html|str]]  | | 
|  | | character(n), char(n)  | n+1 or n+4 bytes  | fixed-length character string  |  | [[http://docs.diesel.rs/diesel/sql_types/struct.Text.html|Text]]  | [[https://doc.rust-lang.org/std/string/struct.String.html|String]], &[[https://doc.rust-lang.org/std/primitive.str.html|str]]  | | 
|  | | text  | n+1 or n+4 bytes  | variable-length character string  |  | [[http://docs.diesel.rs/diesel/sql_types/struct.Text.html|Text]]  | [[https://doc.rust-lang.org/std/string/struct.String.html|String]], &[[https://doc.rust-lang.org/std/primitive.str.html|str]]  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-binary.html|Binary Data Types]]  ^^^^^^ | 
|  | | bytea  | n+1 to n+4 bytes  | binary data ("byte array")  |  | [[http://docs.diesel.rs/diesel/sql_types/struct.Binary.html|Binary]]  | [[https://doc.rust-lang.org/std/vec/struct.Vec.html|Vec]]<[[https://doc.rust-lang.org/std/primitive.u8.html|u8]]>, &[[https://doc.rust-lang.org/std/primitive.u8.html|u8]]  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-datetime.html|Date/Time Types]]  ^^^^^^ | 
|  | | timestamp, timestamp(p) without time zone | 8 bytes  | date and time of day  | 4713 BC to 294276 AD, 1 microsecond  | [[http://docs.diesel.rs/diesel/sql_types/struct.Timestamp.html|Timestamp]]  | [[http://docs.diesel.rs/chrono/naive/struct.NaiveDateTime.html|chrono::NaiveDateTime]]  | | 
|  | | timestamptz, timestamp(p) with time zone  | 8 bytes  | date and time of day, with time zone  | 4713 BC to 294276 AD, 1 microsecond  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Timestamptz.html|Timestamptz]]  | [[http://docs.diesel.rs/chrono/struct.DateTime.html|chrono::DateTime]]  | | 
|  | | date  | 4 bytes  | calendar date (year, month, day)  | 4713 BC to 5874897 AD, 1 day  | [[http://docs.diesel.rs/diesel/sql_types/struct.Date.html|Date]]  | [[http://docs.diesel.rs/chrono/naive/struct.NaiveDate.html|chrono::NaiveDate]]  | | 
|  | | time, time(p) without time zone  | 8 bytes  | time of day (no date)  | 00:00:00 to 24:00:00, 1 microsecond  | [[http://docs.diesel.rs/diesel/sql_types/struct.Time.html|Time]]  | [[http://docs.diesel.rs/chrono/naive/struct.NaiveTime.html|chrono::NaiveTime]]  | | 
|  | | timetz, time(p) with time zone  | 12 bytes  | time of day (no date), with time zone  | 00:00:00+1459 to 24:00:00-1459, 1 microsecond  |  | | 
|  | | interval(fields)(p)  | 16 bytes  | time span  | -178000000 years to 178000000 years, 1 microsecond | [[http://docs.diesel.rs/diesel/sql_types/struct.Interval.html|Interval]]  | [[http://docs.diesel.rs/diesel/pg/data_types/struct.PgInterval.html|PgInterval]]  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-boolean.html|Boolean Type]]  ^^^^^^ | 
|  | | boolean, bool  | 1 byte  | logical Boolean (true/false)  |  | [[http://docs.diesel.rs/diesel/sql_types/struct.Bool.html|Bool]]  | [[https://doc.rust-lang.org/std/primitive.bool.html|bool]]  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-geometric.html|Geometric Types]]  ^^^^^^ | 
|  | | point (x,y)  | 16 bytes  | geometric point on a plane  |  | | 
|  | | line {A,B,C}  | 32 bytes  | infinite line on a plane  |  | | 
|  | | lseg ((x1,y1),(x2,y2))  | 32 bytes  | finite line segment on a plane  |  | | 
|  | | box ((x1,y1),(x2,y2))  | 32 bytes  | rectangular box on a plane  |  | | 
|  | | path ((x1,y1),...)  | 16+16n bytes  | closed geometric path on a plane  |  | | 
|  | | path [(x1,y1),...]  | 16+16n bytes  | open geometric path on a plane  |  | | 
|  | | polygon ((x1,y1),...)  | 40+16n bytes  | closed geometric path on a plane  |  | | 
|  | | circle <(x,y),r\>  | 24 bytes  | circle on a plane  |  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-net-types.html|Network Address Types]]  ^^^^^^ | 
|  | | cidr  | 7 or 19 bytes  | IPv4 or IPv6 network address  |  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Cidr.html|Cidr]]  | [[http://docs.diesel.rs/ipnetwork/enum.IpNetwork.html|ipnetwork::IpNetwork]]  | | 
|  | | inet  | 7 or 19 bytes  | IPv4 or IPv6 host address  |  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Inet.html|Inet]]  | [[http://docs.diesel.rs/ipnetwork/enum.IpNetwork.html|ipnetwork::IpNetwork]]  | | 
|  | | macaddr  | 6 bytes  | MAC address  |  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.MacAddr.html|MacAddr]]  | %%[%%[[https://doc.rust-lang.org/std/primitive.u8.html|u8]]; 6]  | | 
|  | | macaddr8  | 8 bytes  | MAC address (EUI-64 format)  |  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-enum.html|Enumerated Types]]  ^^^^^^ | 
|  | | enum  | 4 bytes  | enumerated value  |  | (user-defined)  | [[https://doc.rust-lang.org/std/string/struct.String.html|String]], [[https://doc.rust-lang.org/book/first-edition/enums.html|enum]]  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-bit.html|Bit String Types]]  ^^^^^^ | 
|  | | bit(n)  | 1 byte per 8 bits + 5 or 8 bytes  | fixed-length bit string  |  | | 
|  | | bit varying(n), varbit  | 1 byte per 8 bits + 5 or 8 bytes  | variable-length bit string  |  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-textsearch.html|Text Search Types]]  ^^^^^^ | 
|  | | tsvector  |  | text search document  |  | TsVector  | | 
|  | | tsquery  |  | text search query  |  | TsQuery  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-uuid.html|UUID Type]]  ^^^^^^ | 
|  | | uuid  | 16 bytes  | universally unique identifier  |  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Uuid.html|Uuid]]  | [[https://docs.rs/uuid/0.5.1/uuid/struct.Uuid.html|uuid::Uuid]]  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-xml.html|XML Type]]  ^^^^^^ | 
|  | | xml  |  | XML data  |  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/datatype-json.html|JSON Types]]  ^^^^^^ | 
|  | | json  |  | textual JSON data  |  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Json.html|Json]]  | [[http://docs.diesel.rs/serde_json/value/enum.Value.html|serde_json::Value]]  | | 
|  | | jsonb  |  | binary JSON data, decomposed  |  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Jsonb.html|Jsonb]]  | [[http://docs.diesel.rs/serde_json/value/enum.Value.html|serde_json::Value]]  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/arrays.html|Arrays]]  ^^^^^^ | 
|  | | t[]  |  | array of values  |  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Array.html|Array]]<T>  | [[https://doc.rust-lang.org/std/vec/struct.Vec.html|Vec]]<T>, [[https://doc.rust-lang.org/std/vec/struct.Vec.html|Vec]]<[[https://doc.rust-lang.org/std/option/enum.Option.html|Option]]<T>>, &[T], &%%[%%[[https://doc.rust-lang.org/std/option/enum.Option.html|Option]]<T>]  | | 
|  | ^ [[https://www.postgresql.org/docs/current/static/rangetypes.html|Range Types]]  ^^^^^^ | 
|  | | int4range  |  | range of integer  |  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Range.html|Range]]<[[http://docs.diesel.rs/diesel/sql_types/struct.Integer.html|Integer]]>  | ([[https://doc.rust-lang.org/std/collections/enum.Bound.html|Bound]]<[[https://doc.rust-lang.org/std/primitive.i32.html|i32]]>, [[https://doc.rust-lang.org/std/collections/enum.Bound.html|Bound]]<[[https://doc.rust-lang.org/std/primitive.i32.html|i32]]>) | 
|  | | int8range  |  | range of bigint  |  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Range.html|Range]]<[[http://docs.diesel.rs/diesel/sql_types/struct.BigInt.html|BigInt]]>  | ([[https://doc.rust-lang.org/std/collections/enum.Bound.html|Bound]]<[[https://doc.rust-lang.org/std/primitive.i64.html|i64]]>, [[https://doc.rust-lang.org/std/collections/enum.Bound.html|Bound]]<[[https://doc.rust-lang.org/std/primitive.i64.html|i64]]>) | 
|  | | numrange  |  | range of numeric  |  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Range.html|Range]]<[[http://docs.diesel.rs/diesel/sql_types/struct.Numeric.html|Numeric]]>  | ([[https://doc.rust-lang.org/std/collections/enum.Bound.html|Bound]]<[[http://docs.diesel.rs/bigdecimal/struct.BigDecimal.html|bigdecimal::BigDecimal]]>, [[https://doc.rust-lang.org/std/collections/enum.Bound.html|Bound]]<[[http://docs.diesel.rs/bigdecimal/struct.BigDecimal.html|bigdecimal::BigDecimal]]>) | 
|  | | tsrange  |  | range of timestamp  |  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Range.html|Range]]<[[http://docs.diesel.rs/diesel/sql_types/struct.Timestamp.html|Timestamp]]>  | ([[https://doc.rust-lang.org/std/collections/enum.Bound.html|Bound]]<[[http://docs.diesel.rs/chrono/naive/struct.NaiveDateTime.html|chrono::NaiveDateTime]]>, [[https://doc.rust-lang.org/std/collections/enum.Bound.html|Bound]]<[[http://docs.diesel.rs/chrono/naive/struct.NaiveDateTime.html|chrono::NaiveDateTime]]>) | 
|  | | tstzrange  |  | range of timestamptz  |  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Range.html|Range]]<[[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Timestamptz.html|Timestamptz]]> | ([[https://doc.rust-lang.org/std/collections/enum.Bound.html|Bound]]<[[http://docs.diesel.rs/chrono/struct.DateTime.html|chrono::DateTime]]>, [[https://doc.rust-lang.org/std/collections/enum.Bound.html|Bound]]<[[http://docs.diesel.rs/chrono/struct.DateTime.html|chrono::DateTime]]>) | 
|  | | daterange  |  | range of date  |  | [[http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Range.html|Range]]<[[http://docs.diesel.rs/diesel/sql_types/struct.Date.html|Date]]>  | ([[https://doc.rust-lang.org/std/collections/enum.Bound.html|Bound]]<[[http://docs.diesel.rs/chrono/naive/struct.NaiveDate.html|chrono::NaiveDate]]>, [[https://doc.rust-lang.org/std/collections/enum.Bound.html|Bound]]<[[http://docs.diesel.rs/chrono/naive/struct.NaiveDate.html|chrono::NaiveDate]]>)  | | 
|  | </WRAP> | 
|  | === 参考文献 === | 
|  | [[so>questions/70410103/how-to-make-diesel-auto-generate-models|rust - How to make Diesel auto-generate models? - Stack Overflow]] [[gtr>https://stackoverflow.com/questions/70410103/how-to-make-diesel-auto-generate-models|翻訳]]\\ | 
|  | [[https://kotiri.com/2018/01/31/postgresql-diesel-rust-types.html|A comprehensive mapping of PostgreSQL, Diesel, and Rust types]]\\ | 
|  |  |