§
    ÝŸ’jÜ	  ã                  ó:   — d dl mZ dZdZdZdZdZdZdZd	Z	d
Z
dZdS )é    )ÚannotationsaA  
INSERT INTO zalo_accounts (id, name, phone_number, created_at, updated_at)
VALUES (%(id)s, %(name)s, %(phone_number)s, COALESCE(%(created_at)s, NOW()), COALESCE(%(updated_at)s, NOW()))
ON CONFLICT (id) DO UPDATE SET
    name = EXCLUDED.name,
    phone_number = EXCLUDED.phone_number,
    updated_at = NOW()
RETURNING *;
a‚  
INSERT INTO contacts (id, name, phone_number, is_internal, created_at, updated_at)
VALUES (%(id)s, %(name)s, %(phone_number)s, %(is_internal)s, COALESCE(%(created_at)s, NOW()), COALESCE(%(updated_at)s, NOW()))
ON CONFLICT (id) DO UPDATE SET
    name = EXCLUDED.name,
    phone_number = EXCLUDED.phone_number,
    is_internal = EXCLUDED.is_internal,
    updated_at = NOW()
RETURNING *;
a«  
INSERT INTO conversations (id, zalo_account_id, contact_id, is_internal, created_at, updated_at)
VALUES (%(id)s, %(zalo_account_id)s, %(contact_id)s, %(is_internal)s, COALESCE(%(created_at)s, NOW()), COALESCE(%(updated_at)s, NOW()))
ON CONFLICT (id) DO UPDATE SET
    zalo_account_id = EXCLUDED.zalo_account_id,
    contact_id = EXCLUDED.contact_id,
    is_internal = EXCLUDED.is_internal,
    updated_at = NOW()
RETURNING *;
zÆ
INSERT INTO messages (id, conversation_id, sender_type, sender_id, content, timestamp)
VALUES (%(id)s, %(conversation_id)s, %(sender_type)s, %(sender_id)s, %(content)s, %(timestamp)s)
RETURNING *;
a   
INSERT INTO telegram_topic_maps (id, conversation_id, telegram_topic_id, telegram_group_id, created_at)
VALUES (%(id)s, %(conversation_id)s, %(telegram_topic_id)s, %(telegram_group_id)s, COALESCE(%(created_at)s, NOW()))
ON CONFLICT (id) DO UPDATE SET
    conversation_id = EXCLUDED.conversation_id,
    telegram_topic_id = EXCLUDED.telegram_topic_id,
    telegram_group_id = EXCLUDED.telegram_group_id
RETURNING *;
z3
SELECT * FROM contacts WHERE is_internal = FALSE;
z
SELECT * FROM contacts;
z\
SELECT * FROM messages WHERE conversation_id = %(conversation_id)s ORDER BY timestamp ASC;
zX
SELECT * FROM telegram_topic_maps WHERE conversation_id = %(conversation_id)s LIMIT 1;
z\
SELECT * FROM telegram_topic_maps WHERE telegram_topic_id = %(telegram_topic_id)s LIMIT 1;
N)Ú
__future__r   ÚUPSERT_ZALO_ACCOUNTÚUPSERT_CONTACTÚUPSERT_CONVERSATIONÚINSERT_MESSAGEÚUPSERT_TELEGRAM_TOPIC_MAPÚGET_EXTERNAL_CONTACTSÚGET_ALL_CONTACTSÚGET_MESSAGES_BY_CONVERSATIONÚ"GET_TELEGRAM_TOPIC_BY_CONVERSATIONÚGET_TELEGRAM_TOPIC_BY_ID© ó    ú3C:\Projects\DSCons\app\core\postgres\crm\queries.pyú<module>r      sk   ðØ "Ð "Ð "Ð "Ð "Ð "ðÐ ð	€ð	Ð ð€ðÐ ðÐ ðÐ ð Ð ð&Ð "ðÐ Ð Ð r   