users: get user by id, email, username
This commit is contained in:
parent
b8f6cae85e
commit
d790d2ff29
8 changed files with 254 additions and 6 deletions
14
crates/database/queries/users/get_one_by_email.sql
Normal file
14
crates/database/queries/users/get_one_by_email.sql
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
select id,
|
||||
created_at as "created_at: DateTime<Utc>",
|
||||
updated_at as "updated_at: DateTime<Utc>",
|
||||
is_admin as "is_admin: bool",
|
||||
username,
|
||||
name,
|
||||
email,
|
||||
password,
|
||||
password_recover,
|
||||
paper_key,
|
||||
is_archived as "is_archived: bool"
|
||||
from users
|
||||
|
||||
where email is (?)
|
||||
14
crates/database/queries/users/get_one_by_username.sql
Normal file
14
crates/database/queries/users/get_one_by_username.sql
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
select id,
|
||||
created_at as "created_at: DateTime<Utc>",
|
||||
updated_at as "updated_at: DateTime<Utc>",
|
||||
is_admin as "is_admin: bool",
|
||||
username,
|
||||
name,
|
||||
email,
|
||||
password,
|
||||
password_recover,
|
||||
paper_key,
|
||||
is_archived as "is_archived: bool"
|
||||
from users
|
||||
|
||||
where username is (?)
|
||||
|
|
@ -88,6 +88,84 @@
|
|||
},
|
||||
"query": "select id,\n created_at as \"created_at: DateTime<Utc>\",\n updated_at as \"updated_at: DateTime<Utc>\",\n business_name,\n business_logo,\n url\n\nfrom settings\n\nwhere id is 0\n"
|
||||
},
|
||||
"69752cc2a3fc91d4e7a39e0b167695f431380bd40df9638b5df3534715de04b0": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "created_at: DateTime<Utc>",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "updated_at: DateTime<Utc>",
|
||||
"ordinal": 2,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "is_admin: bool",
|
||||
"ordinal": 3,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "username",
|
||||
"ordinal": 4,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"ordinal": 5,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "email",
|
||||
"ordinal": 6,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "password",
|
||||
"ordinal": 7,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "password_recover",
|
||||
"ordinal": 8,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "paper_key",
|
||||
"ordinal": 9,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "is_archived: bool",
|
||||
"ordinal": 10,
|
||||
"type_info": "Int64"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
}
|
||||
},
|
||||
"query": "select id,\n created_at as \"created_at: DateTime<Utc>\",\n updated_at as \"updated_at: DateTime<Utc>\",\n is_admin as \"is_admin: bool\",\n username,\n name,\n email,\n password,\n password_recover,\n paper_key,\n is_archived as \"is_archived: bool\"\nfrom users\n\nwhere email is (?)\n"
|
||||
},
|
||||
"87906834faa6f185aee0e4d893b9754908b1c173e9dce383663d723891a89cd1": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
|
|
@ -108,6 +186,84 @@
|
|||
},
|
||||
"query": "update settings\n\nset first_admin = ?\n\nwhere id is 0\n"
|
||||
},
|
||||
"b652e67e8e1cd0e2b55c830c5569eb1c6caf73857215b4298265cce5c5462902": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "created_at: DateTime<Utc>",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "updated_at: DateTime<Utc>",
|
||||
"ordinal": 2,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "is_admin: bool",
|
||||
"ordinal": 3,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "username",
|
||||
"ordinal": 4,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"ordinal": 5,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "email",
|
||||
"ordinal": 6,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "password",
|
||||
"ordinal": 7,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "password_recover",
|
||||
"ordinal": 8,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "paper_key",
|
||||
"ordinal": 9,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "is_archived: bool",
|
||||
"ordinal": 10,
|
||||
"type_info": "Int64"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
}
|
||||
},
|
||||
"query": "select id,\n created_at as \"created_at: DateTime<Utc>\",\n updated_at as \"updated_at: DateTime<Utc>\",\n is_admin as \"is_admin: bool\",\n username,\n name,\n email,\n password,\n password_recover,\n paper_key,\n is_archived as \"is_archived: bool\"\nfrom users\n\nwhere username is (?)\n"
|
||||
},
|
||||
"c5a57c971d07532ec0cc897b5ac06e0814e506f9c24647d1eaf44174dc0a5954": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
|
|
|
|||
|
|
@ -51,4 +51,24 @@ impl Users {
|
|||
.await
|
||||
.map_err(handle_error)
|
||||
}
|
||||
|
||||
pub async fn get_one_by_email(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
email: &str,
|
||||
) -> Result<Option<Self>, Error> {
|
||||
sqlx::query_file_as!(Self, "queries/users/get_one_by_email.sql", email)
|
||||
.fetch_optional(conn)
|
||||
.await
|
||||
.map_err(handle_error)
|
||||
}
|
||||
|
||||
pub async fn get_one_by_username(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
username: &str,
|
||||
) -> Result<Option<Self>, Error> {
|
||||
sqlx::query_file_as!(Self, "queries/users/get_one_by_username.sql", username)
|
||||
.fetch_optional(conn)
|
||||
.await
|
||||
.map_err(handle_error)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue