11use crate :: codec:: BackendMessages ;
22use crate :: connection:: { Request , RequestMessages } ;
33use crate :: prepare:: prepare;
4- use crate :: types:: Type ;
4+ use crate :: types:: { Oid , Type } ;
55use crate :: { Error , Statement } ;
66use fallible_iterator:: FallibleIterator ;
77use futures:: channel:: mpsc;
88use futures:: { Stream , StreamExt } ;
9+ use parking_lot:: Mutex ;
910use postgres_protocol:: message:: backend:: Message ;
11+ use std:: collections:: HashMap ;
1012use std:: future:: Future ;
1113use std:: pin:: Pin ;
1214use std:: sync:: Arc ;
@@ -34,8 +36,16 @@ impl Responses {
3436 }
3537}
3638
39+ struct State {
40+ has_typeinfo : bool ,
41+ has_typeinfo_composite : bool ,
42+ has_typeinfo_enum : bool ,
43+ types : HashMap < Oid , Type > ,
44+ }
45+
3746pub struct InnerClient {
3847 sender : mpsc:: UnboundedSender < Request > ,
48+ state : Mutex < State > ,
3949}
4050
4151impl InnerClient {
@@ -51,6 +61,38 @@ impl InnerClient {
5161 cur : BackendMessages :: empty ( ) ,
5262 } )
5363 }
64+
65+ pub fn has_typeinfo ( & self ) -> bool {
66+ self . state . lock ( ) . has_typeinfo
67+ }
68+
69+ pub fn set_has_typeinfo ( & self ) {
70+ self . state . lock ( ) . has_typeinfo = true ;
71+ }
72+
73+ pub fn has_typeinfo_composite ( & self ) -> bool {
74+ self . state . lock ( ) . has_typeinfo_composite
75+ }
76+
77+ pub fn set_has_typeinfo_composite ( & self ) {
78+ self . state . lock ( ) . has_typeinfo_composite = true ;
79+ }
80+
81+ pub fn has_typeinfo_enum ( & self ) -> bool {
82+ self . state . lock ( ) . has_typeinfo_enum
83+ }
84+
85+ pub fn set_has_typeinfo_enum ( & self ) {
86+ self . state . lock ( ) . has_typeinfo_enum = true ;
87+ }
88+
89+ pub fn type_ ( & self , oid : Oid ) -> Option < Type > {
90+ self . state . lock ( ) . types . get ( & oid) . cloned ( )
91+ }
92+
93+ pub fn set_type ( & self , oid : Oid , type_ : Type ) {
94+ self . state . lock ( ) . types . insert ( oid, type_) ;
95+ }
5496}
5597
5698pub struct Client {
@@ -66,7 +108,15 @@ impl Client {
66108 secret_key : i32 ,
67109 ) -> Client {
68110 Client {
69- inner : Arc :: new ( InnerClient { sender } ) ,
111+ inner : Arc :: new ( InnerClient {
112+ sender,
113+ state : Mutex :: new ( State {
114+ has_typeinfo : false ,
115+ has_typeinfo_composite : false ,
116+ has_typeinfo_enum : false ,
117+ types : HashMap :: new ( ) ,
118+ } ) ,
119+ } ) ,
70120 process_id,
71121 secret_key,
72122 }
0 commit comments