Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa7709d

Browse files
committed
Add support for Postgres money type
1 parentf9ba589 commitaa7709d

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

‎postgres-protocol/src/types/mod.rs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,22 @@ pub fn uuid_from_sql(buf: &[u8]) -> Result<[u8; 16], StdBox<dyn Error + Sync + S
441441
Ok(out)
442442
}
443443

444+
/// Serializes a `Money` value.
445+
#[inline]
446+
pubfnmoney_to_sql(v:i64,buf:&mutBytesMut){
447+
buf.put_i64(v);
448+
}
449+
450+
/// Deserializes a `Money` value.
451+
#[inline]
452+
pubfnmoney_from_sql(mutbuf:&[u8]) ->Result<i64,StdBox<dynError +Sync +Send>>{
453+
let v = buf.read_i64::<BigEndian>()?;
454+
if !buf.is_empty(){
455+
returnErr("invalid buffer size".into());
456+
}
457+
Ok(v)
458+
}
459+
444460
/// Serializes an array value.
445461
#[inline]
446462
pubfnarray_to_sql<T,I,J,F>(

‎postgres-types/Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ with-bit-vec-0_6 = ["bit-vec-06"]
1616
with-chrono-0_4 = ["chrono-04"]
1717
with-eui48-0_4 = ["eui48-04"]
1818
with-geo-types-0_4 = ["geo-types-04"]
19+
with-money-0_1 = ["money-01"]
1920
with-serde_json-1 = ["serde-1","serde_json-1"]
2021
with-uuid-0_8 = ["uuid-08"]
2122
with-time-0_2 = ["time-02"]
@@ -30,6 +31,7 @@ bit-vec-06 = { version = "0.6", package = "bit-vec", optional = true }
3031
chrono-04 = {version ="0.4",package ="chrono",optional =true }
3132
eui48-04 = {version ="0.4",package ="eui48",optional =true }
3233
geo-types-04 = {version ="0.4",package ="geo-types",optional =true }
34+
money-01 = {version ="0.2",package ="postgres_money",optional =true }
3335
serde-1 = {version ="1.0",package ="serde",optional =true }
3436
serde_json-1 = {version ="1.0",package ="serde_json",optional =true }
3537
uuid-08 = {version ="0.8",package ="uuid",optional =true }

‎postgres-types/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ mod chrono_04;
196196
mod eui48_04;
197197
#[cfg(feature ="with-geo-types-0_4")]
198198
mod geo_types_04;
199+
#[cfg(feature ="with-money-0_1")]
200+
mod money_01;
199201
#[cfg(feature ="with-serde_json-1")]
200202
mod serde_json_1;
201203
#[cfg(feature ="with-time-0_2")]

‎postgres-types/src/money_01.rs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use bytes::BytesMut;
2+
use std::error::Error;
3+
use postgres_protocol::types;
4+
use money_01::Money;
5+
6+
usecrate::{FromSql,IsNull,ToSql,Type};
7+
8+
impl<'a>FromSql<'a>forMoney{
9+
fnfrom_sql(_:&Type,raw:&[u8]) ->Result<Money,Box<dynError +Sync +Send>>{
10+
let inner = types::money_from_sql(raw)?;
11+
Ok(Money::from(inner))
12+
}
13+
14+
accepts!(MONEY);
15+
}
16+
17+
implToSqlforMoney{
18+
fnto_sql(&self, _:&Type,w:&mutBytesMut) ->Result<IsNull,Box<dynError +Sync +Send>>{
19+
types::money_to_sql(self.inner(), w);
20+
Ok(IsNull::No)
21+
}
22+
23+
accepts!(MONEY);
24+
to_sql_checked!();
25+
}

‎tokio-postgres/Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ with-bit-vec-0_6 = ["postgres-types/with-bit-vec-0_6"]
3131
with-chrono-0_4 = ["postgres-types/with-chrono-0_4"]
3232
with-eui48-0_4 = ["postgres-types/with-eui48-0_4"]
3333
with-geo-types-0_4 = ["postgres-types/with-geo-types-0_4"]
34+
with-money-0_1 = ["postgres-types/with-money-0_1"]
3435
with-serde_json-1 = ["postgres-types/with-serde_json-1"]
3536
with-uuid-0_8 = ["postgres-types/with-uuid-0_8"]
3637
with-time-0_2 = ["postgres-types/with-time-0_2"]
@@ -60,6 +61,7 @@ bit-vec-06 = { version = "0.6", package = "bit-vec" }
6061
chrono-04 = {version ="0.4",package ="chrono" }
6162
eui48-04 = {version ="0.4",package ="eui48" }
6263
geo-types-04 = {version ="0.4",package ="geo-types" }
64+
money-01 = {version ="0.2",package ="postgres_money" }
6365
serde-1 = {version ="1.0",package ="serde" }
6466
serde_json-1 = {version ="1.0",package ="serde_json" }
6567
uuid-08 = {version ="0.8",package ="uuid" }

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp