migrate sql queries to postgres
This commit is contained in:
parent
d40b396f4f
commit
6def619161
2 changed files with 8 additions and 8 deletions
|
|
@ -5,8 +5,8 @@ use crate::unwrap_or_create;
|
||||||
|
|
||||||
pub async fn create_chat(db: &DbPool, chat: &types::Chat) -> Result<Chat, sqlx::Error> {
|
pub async fn create_chat(db: &DbPool, chat: &types::Chat) -> Result<Chat, sqlx::Error> {
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"INSERT INTO chat (tg_id,title,username,can_download)
|
r#"INSERT INTO "chat" (tg_id,title,username,can_download)
|
||||||
VALUES ($1,$2,$3,$4)",
|
VALUES ($1,$2,$3,$4)"#,
|
||||||
)
|
)
|
||||||
.bind(chat.id.0 as i64)
|
.bind(chat.id.0 as i64)
|
||||||
.bind(chat.title())
|
.bind(chat.title())
|
||||||
|
|
@ -15,7 +15,7 @@ pub async fn create_chat(db: &DbPool, chat: &types::Chat) -> Result<Chat, sqlx::
|
||||||
.execute(db)
|
.execute(db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let chat: Chat = sqlx::query_as("SELECT * FROM chat WHERE tg_id = $1 LIMIT 1;")
|
let chat: Chat = sqlx::query_as(r#"SELECT * FROM "chat" WHERE tg_id = $1 LIMIT 1;"#)
|
||||||
.bind(chat.id.0 as i64)
|
.bind(chat.id.0 as i64)
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
@ -24,7 +24,7 @@ pub async fn create_chat(db: &DbPool, chat: &types::Chat) -> Result<Chat, sqlx::
|
||||||
|
|
||||||
pub async fn find_or_create_chat(db: &DbPool, chat: &types::Chat) -> Result<Chat, sqlx::Error> {
|
pub async fn find_or_create_chat(db: &DbPool, chat: &types::Chat) -> Result<Chat, sqlx::Error> {
|
||||||
let res: Result<Chat, sqlx::Error> =
|
let res: Result<Chat, sqlx::Error> =
|
||||||
sqlx::query_as("SELECT * FROM chat WHERE tg_id = $1 LIMIT 1;")
|
sqlx::query_as(r#"SELECT * FROM "chat" WHERE tg_id = $1 LIMIT 1;"#)
|
||||||
.bind(chat.id.0 as i64)
|
.bind(chat.id.0 as i64)
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
.await;
|
.await;
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@ pub async fn create_user(
|
||||||
is_admin: bool,
|
is_admin: bool,
|
||||||
) -> Result<User, sqlx::Error> {
|
) -> Result<User, sqlx::Error> {
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"INSERT OR IGNORE INTO user
|
r#"INSERT OR IGNORE INTO "user"
|
||||||
(tg_id, username, first_name, last_name, can_download, is_admin, has_private_chat)
|
(tg_id, username, first_name, last_name, can_download, is_admin, has_private_chat)
|
||||||
VALUES ($1,$2,$3,$4,$5,$6,$7);",
|
VALUES ($1,$2,$3,$4,$5,$6,$7);"#,
|
||||||
)
|
)
|
||||||
.bind(user.id.0 as i64)
|
.bind(user.id.0 as i64)
|
||||||
.bind(&user.username)
|
.bind(&user.username)
|
||||||
|
|
@ -24,7 +24,7 @@ pub async fn create_user(
|
||||||
.execute(db)
|
.execute(db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let user: User = sqlx::query_as("SELECT * FROM user WHERE tg_id = $1 LIMIT 1;")
|
let user: User = sqlx::query_as(r#"SELECT * FROM "user" WHERE tg_id = $1 LIMIT 1;"#)
|
||||||
.bind(user.id.0 as i64)
|
.bind(user.id.0 as i64)
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
@ -33,7 +33,7 @@ pub async fn create_user(
|
||||||
|
|
||||||
pub async fn find_or_create_user(db: &DbPool, user: &types::User) -> Result<User, sqlx::Error> {
|
pub async fn find_or_create_user(db: &DbPool, user: &types::User) -> Result<User, sqlx::Error> {
|
||||||
let res: Result<User, sqlx::Error> =
|
let res: Result<User, sqlx::Error> =
|
||||||
sqlx::query_as("SELECT * FROM user WHERE tg_id = $1 LIMIT 1;")
|
sqlx::query_as(r#"SELECT * FROM "user" WHERE tg_id = $1 LIMIT 1;"#)
|
||||||
.bind(user.id.0 as i64)
|
.bind(user.id.0 as i64)
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
.await;
|
.await;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue