refactor: add standalone PgOid type

This commit is contained in:
Jindřich Moravec 2024-02-01 22:27:58 +01:00
parent bdb6a955df
commit 6d1af26fa8
10 changed files with 136 additions and 66 deletions

View file

@ -11,8 +11,6 @@ anyhow = "1.0.76"
clap = { version = "4.4.18", features = ["derive"] }
async-trait = "0.1.74"
rand = "0.8.5"
rand_seeder = "0.2.3"
rand_pcg = "0.3.1"
serde_json = "1.0.112"
minisql = { path = "../minisql" }
proto = { path = "../proto" }

View file

@ -7,10 +7,8 @@ use proto::message::backend::{
ReadyForQueryData, RowDescriptionData,
};
use proto::message::primitive::pglist::PgList;
use proto::message::primitive::pgoid::PgOid;
use proto::writer::backend::BackendProtoWriter;
use rand::Rng;
use rand_pcg::Pcg64;
use rand_seeder::Seeder;
use std::fmt;
pub enum CompleteStatus {
@ -123,7 +121,7 @@ fn column_to_description(
column: Column,
) -> anyhow::Result<ColumnDescription> {
let table_name = schema.table_name();
let table_oid = table_name_to_oid(table_name);
let table_oid = PgOid::from_unique_name(table_name);
let column_type = schema.column_type(column);
let name = schema.column_name_from_column(column);
@ -142,10 +140,3 @@ fn column_to_description(
format_code: 0, // text format
})
}
/// Hashes the table name into single i32 used as a substitute for the table OID
/// in the PostgreSQL protocol.
fn table_name_to_oid(table_name: &str) -> i32 {
let mut rng: Pcg64 = Seeder::from(table_name).make_rng();
rng.gen::<i32>()
}