Skip to content

Commit

Permalink
Switch (back) to postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Cordry committed Feb 15, 2024
1 parent 9b06133 commit dc4be5f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions backend/src/import.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::dat::{Config, Reader};
use crate::model::{ClassRecord, InstructorRecord, MeetingRecord, ToRow};
use sqlx::{prelude::*, Pool, MySql, QueryBuilder};
use sqlx::{prelude::*, Pool, Postgres, QueryBuilder};
use std::io::BufReader;

const BIND_LIMIT: usize = 65535;

pub async fn import(pool: &Pool<MySql>) -> Result<(), sqlx::Error> {
pub async fn import(pool: &Pool<Postgres>) -> Result<(), sqlx::Error> {
let mut connection = pool.acquire().await?;
connection
.transaction(|transaction| {
Expand Down
10 changes: 5 additions & 5 deletions backend/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
//! backend queries for its information.

use serde::{Deserialize, Serialize};
use sqlx::{mysql, query_builder::Separated, types::chrono, FromRow, MySql};
use sqlx::{mysql, query_builder::Separated, types::chrono, FromRow, Postgres};
use std::fmt::Display;
use utoipa::ToSchema;

pub trait ToRow {
fn keys() -> &'static [&'static str];
fn bind<'qb, 'args: 'qb, Sep: Display>(
&self,
query_builder: &mut Separated<'qb, 'args, MySql, Sep>,
query_builder: &mut Separated<'qb, 'args, Postgres, Sep>,
);
}

trait ToEncode<'a, T: sqlx::Type<MySql> + sqlx::Encode<'a, MySql>> {
trait ToEncode<'a, T: sqlx::Type<Postgres> + sqlx::Encode<'a, Postgres>> {
fn to_encode(&self) -> T;
}

impl<'a, T: sqlx::Type<MySql> + sqlx::Encode<'a, MySql> + Clone> ToEncode<'a, T> for T {
impl<'a, T: sqlx::Type<Postgres> + sqlx::Encode<'a, Postgres> + Clone> ToEncode<'a, T> for T {
fn to_encode(&self) -> T {
self.clone()
}
Expand Down Expand Up @@ -61,7 +61,7 @@ macro_rules! generate_to_row {

fn bind<'qb, 'args: 'qb, Sep: Display>(
&self,
query_builder: &mut Separated<'qb, 'args, MySql, Sep>
query_builder: &mut Separated<'qb, 'args, Postgres, Sep>
) {
query_builder
$(.push_bind(self.$field_name.to_encode()))*;
Expand Down

0 comments on commit dc4be5f

Please sign in to comment.