// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: contact.sql package sqlcgen import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const deleteContacts = `-- name: DeleteContacts :one WITH deleted AS ( DELETE FROM contacts WHERE user_id = $1::bigint AND contact_user_id = ANY($2::bigint[]) RETURNING contact_user_id ), reverse_updated AS ( UPDATE contacts c SET mutual = false, updated_at = now() FROM deleted d WHERE c.user_id = d.contact_user_id AND c.contact_user_id = $1::bigint RETURNING c.user_id ) SELECT COUNT(*)::int AS deleted_count FROM deleted ` type DeleteContactsParams struct { UserID int64 ContactUserIds []int64 } func (q *Queries) DeleteContacts(ctx context.Context, arg DeleteContactsParams) (int32, error) { row := q.db.QueryRow(ctx, deleteContacts, arg.UserID, arg.ContactUserIds) var deleted_count int32 err := row.Scan(&deleted_count) return deleted_count, err } const getContact = `-- name: GetContact :one SELECT c.contact_user_id, c.mutual, c.close_friend, c.contact_phone, c.contact_first_name, c.contact_last_name, c.note, COALESCE(c.note_entities::text, '[]')::text AS note_entities_json, u.id, u.access_hash, COALESCE(NULLIF(c.contact_phone, ''), u.phone)::text AS phone, COALESCE(NULLIF(c.contact_first_name, ''), u.first_name)::text AS first_name, COALESCE(c.contact_last_name, u.last_name)::text AS last_name, u.username, u.country_code, u.verified, u.support, u.is_bot, u.bot_info_version, u.premium_expires_at, u.emoji_status_document_id, u.emoji_status_until, u.last_seen_at FROM contacts c JOIN users u ON u.id = c.contact_user_id WHERE c.user_id = $1 AND c.contact_user_id = $2 ` type GetContactParams struct { UserID int64 ContactUserID int64 } type GetContactRow struct { ContactUserID int64 Mutual bool CloseFriend bool ContactPhone string ContactFirstName string ContactLastName string Note string NoteEntitiesJson string ID int64 AccessHash int64 Phone string FirstName string LastName string Username string CountryCode string Verified bool Support bool IsBot bool BotInfoVersion int32 PremiumExpiresAt pgtype.Timestamptz EmojiStatusDocumentID int64 EmojiStatusUntil int64 LastSeenAt int64 } func (q *Queries) GetContact(ctx context.Context, arg GetContactParams) (GetContactRow, error) { row := q.db.QueryRow(ctx, getContact, arg.UserID, arg.ContactUserID) var i GetContactRow err := row.Scan( &i.ContactUserID, &i.Mutual, &i.CloseFriend, &i.ContactPhone, &i.ContactFirstName, &i.ContactLastName, &i.Note, &i.NoteEntitiesJson, &i.ID, &i.AccessHash, &i.Phone, &i.FirstName, &i.LastName, &i.Username, &i.CountryCode, &i.Verified, &i.Support, &i.IsBot, &i.BotInfoVersion, &i.PremiumExpiresAt, &i.EmojiStatusDocumentID, &i.EmojiStatusUntil, &i.LastSeenAt, ) return i, err } const listContactsByUser = `-- name: ListContactsByUser :many SELECT c.contact_user_id, c.mutual, c.close_friend, c.contact_phone, c.contact_first_name, c.contact_last_name, c.note, COALESCE(c.note_entities::text, '[]')::text AS note_entities_json, u.id, u.access_hash, COALESCE(NULLIF(c.contact_phone, ''), u.phone)::text AS phone, COALESCE(NULLIF(c.contact_first_name, ''), u.first_name)::text AS first_name, COALESCE(c.contact_last_name, u.last_name)::text AS last_name, u.username, u.country_code, u.verified, u.support, u.is_bot, u.bot_info_version, u.premium_expires_at, u.emoji_status_document_id, u.emoji_status_until, u.last_seen_at FROM contacts c JOIN users u ON u.id = c.contact_user_id WHERE c.user_id = $1 ORDER BY c.contact_first_name, c.contact_last_name, u.first_name, u.last_name, u.id ` type ListContactsByUserRow struct { ContactUserID int64 Mutual bool CloseFriend bool ContactPhone string ContactFirstName string ContactLastName string Note string NoteEntitiesJson string ID int64 AccessHash int64 Phone string FirstName string LastName string Username string CountryCode string Verified bool Support bool IsBot bool BotInfoVersion int32 PremiumExpiresAt pgtype.Timestamptz EmojiStatusDocumentID int64 EmojiStatusUntil int64 LastSeenAt int64 } func (q *Queries) ListContactsByUser(ctx context.Context, userID int64) ([]ListContactsByUserRow, error) { rows, err := q.db.Query(ctx, listContactsByUser, userID) if err != nil { return nil, err } defer rows.Close() var items []ListContactsByUserRow for rows.Next() { var i ListContactsByUserRow if err := rows.Scan( &i.ContactUserID, &i.Mutual, &i.CloseFriend, &i.ContactPhone, &i.ContactFirstName, &i.ContactLastName, &i.Note, &i.NoteEntitiesJson, &i.ID, &i.AccessHash, &i.Phone, &i.FirstName, &i.LastName, &i.Username, &i.CountryCode, &i.Verified, &i.Support, &i.IsBot, &i.BotInfoVersion, &i.PremiumExpiresAt, &i.EmojiStatusDocumentID, &i.EmojiStatusUntil, &i.LastSeenAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const updateContactNote = `-- name: UpdateContactNote :one WITH updated AS ( UPDATE contacts c SET note = $1::text, note_entities = $2::jsonb, updated_at = now() WHERE c.user_id = $3::bigint AND c.contact_user_id = $4::bigint RETURNING user_id, contact_user_id, mutual, created_at, updated_at, contact_phone, contact_first_name, contact_last_name, note, note_entities, close_friend, stories_hidden, personal_photo_id, personal_photo_date ) SELECT c.contact_user_id, c.mutual, c.close_friend, c.contact_phone, c.contact_first_name, c.contact_last_name, c.note, COALESCE(c.note_entities::text, '[]')::text AS note_entities_json, u.id, u.access_hash, COALESCE(NULLIF(c.contact_phone, ''), u.phone)::text AS phone, COALESCE(NULLIF(c.contact_first_name, ''), u.first_name)::text AS first_name, COALESCE(c.contact_last_name, u.last_name)::text AS last_name, u.username, u.country_code, u.verified, u.support, u.is_bot, u.bot_info_version, u.premium_expires_at, u.emoji_status_document_id, u.emoji_status_until, u.last_seen_at FROM updated c JOIN users u ON u.id = c.contact_user_id ` type UpdateContactNoteParams struct { Note string NoteEntities []byte UserID int64 ContactUserID int64 } type UpdateContactNoteRow struct { ContactUserID int64 Mutual bool CloseFriend bool ContactPhone string ContactFirstName string ContactLastName string Note string NoteEntitiesJson string ID int64 AccessHash int64 Phone string FirstName string LastName string Username string CountryCode string Verified bool Support bool IsBot bool BotInfoVersion int32 PremiumExpiresAt pgtype.Timestamptz EmojiStatusDocumentID int64 EmojiStatusUntil int64 LastSeenAt int64 } func (q *Queries) UpdateContactNote(ctx context.Context, arg UpdateContactNoteParams) (UpdateContactNoteRow, error) { row := q.db.QueryRow(ctx, updateContactNote, arg.Note, arg.NoteEntities, arg.UserID, arg.ContactUserID, ) var i UpdateContactNoteRow err := row.Scan( &i.ContactUserID, &i.Mutual, &i.CloseFriend, &i.ContactPhone, &i.ContactFirstName, &i.ContactLastName, &i.Note, &i.NoteEntitiesJson, &i.ID, &i.AccessHash, &i.Phone, &i.FirstName, &i.LastName, &i.Username, &i.CountryCode, &i.Verified, &i.Support, &i.IsBot, &i.BotInfoVersion, &i.PremiumExpiresAt, &i.EmojiStatusDocumentID, &i.EmojiStatusUntil, &i.LastSeenAt, ) return i, err } const upsertContact = `-- name: UpsertContact :one WITH reverse AS ( SELECT EXISTS ( SELECT 1 FROM contacts WHERE user_id = $1::bigint AND contact_user_id = $2::bigint )::boolean AS mutual ), upserted AS ( INSERT INTO contacts ( user_id, contact_user_id, contact_phone, contact_first_name, contact_last_name, note, note_entities, mutual ) SELECT $2::bigint, $1::bigint, $3::text, $4::text, $5::text, $6::text, $7::jsonb, reverse.mutual FROM reverse ON CONFLICT (user_id, contact_user_id) DO UPDATE SET contact_phone = EXCLUDED.contact_phone, contact_first_name = EXCLUDED.contact_first_name, contact_last_name = EXCLUDED.contact_last_name, note = EXCLUDED.note, note_entities = EXCLUDED.note_entities, mutual = contacts.mutual OR EXCLUDED.mutual, updated_at = now() RETURNING user_id, contact_user_id, mutual, created_at, updated_at, contact_phone, contact_first_name, contact_last_name, note, note_entities, close_friend, stories_hidden, personal_photo_id, personal_photo_date ), reverse_updated AS ( UPDATE contacts c SET mutual = true, updated_at = now() WHERE c.user_id = $1::bigint AND c.contact_user_id = $2::bigint AND NOT c.mutual RETURNING c.user_id ) SELECT c.contact_user_id, c.mutual, c.close_friend, c.contact_phone, c.contact_first_name, c.contact_last_name, c.note, COALESCE(c.note_entities::text, '[]')::text AS note_entities_json, u.id, u.access_hash, COALESCE(NULLIF(c.contact_phone, ''), u.phone)::text AS phone, COALESCE(NULLIF(c.contact_first_name, ''), u.first_name)::text AS first_name, COALESCE(c.contact_last_name, u.last_name)::text AS last_name, u.username, u.country_code, u.verified, u.support, u.is_bot, u.bot_info_version, u.premium_expires_at, u.emoji_status_document_id, u.emoji_status_until, u.last_seen_at, EXISTS (SELECT 1 FROM reverse_updated)::boolean AS reverse_mutual_changed FROM upserted c JOIN users u ON u.id = c.contact_user_id ` type UpsertContactParams struct { ContactUserID int64 UserID int64 ContactPhone string ContactFirstName string ContactLastName string Note string NoteEntities []byte } type UpsertContactRow struct { ContactUserID int64 Mutual bool CloseFriend bool ContactPhone string ContactFirstName string ContactLastName string Note string NoteEntitiesJson string ID int64 AccessHash int64 Phone string FirstName string LastName string Username string CountryCode string Verified bool Support bool IsBot bool BotInfoVersion int32 PremiumExpiresAt pgtype.Timestamptz EmojiStatusDocumentID int64 EmojiStatusUntil int64 LastSeenAt int64 ReverseMutualChanged bool } func (q *Queries) UpsertContact(ctx context.Context, arg UpsertContactParams) (UpsertContactRow, error) { row := q.db.QueryRow(ctx, upsertContact, arg.ContactUserID, arg.UserID, arg.ContactPhone, arg.ContactFirstName, arg.ContactLastName, arg.Note, arg.NoteEntities, ) var i UpsertContactRow err := row.Scan( &i.ContactUserID, &i.Mutual, &i.CloseFriend, &i.ContactPhone, &i.ContactFirstName, &i.ContactLastName, &i.Note, &i.NoteEntitiesJson, &i.ID, &i.AccessHash, &i.Phone, &i.FirstName, &i.LastName, &i.Username, &i.CountryCode, &i.Verified, &i.Support, &i.IsBot, &i.BotInfoVersion, &i.PremiumExpiresAt, &i.EmojiStatusDocumentID, &i.EmojiStatusUntil, &i.LastSeenAt, &i.ReverseMutualChanged, ) return i, err }