File size: 2,421 Bytes
737707b
 
 
7f58bde
737707b
ea48bf9
5eec21a
7f58bde
5eec21a
ea48bf9
288751c
ea48bf9
 
 
288751c
 
ea48bf9
 
7f58bde
 
 
 
746e566
 
 
 
 
ea48bf9
288751c
 
 
 
ea48bf9
7f58bde
288751c
7f58bde
288751c
 
 
7f58bde
5eec21a
288751c
5eec21a
7f58bde
288751c
5eec21a
 
288751c
c98c3bd
5eec21a
7f58bde
5eec21a
288751c
7f58bde
288751c
5eec21a
 
7f58bde
5eec21a
288751c
5eec21a
288751c
5eec21a
288751c
5eec21a
 
 
7f58bde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
"""
J1K OS v2.2 Final Master - Database Configuration
โšก ASYNC Wrapper with HTTP/1.1 Enforcement (To fix Compression Error)
"""
import os
import asyncio
import httpx # ๐Ÿ‘ˆ ุฅุถุงูุฉ ู…ู‡ู…ุฉ
from supabase import create_client
from dotenv import load_dotenv
from supabase.client import ClientOptions

load_dotenv()

url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")

if not url or not key:
    raise ValueError("๐Ÿšจ ูƒุงุฑุซุฉ: ู…ูุงุชูŠุญ ู‚ุงุนุฏุฉ ุงู„ุจูŠุงู†ุงุช ู…ุด ู…ูˆุฌูˆุฏุฉ!")

# ๐Ÿ›ก๏ธ ุฅุฌุจุงุฑ ุงู„ุนู…ูŠู„ ุนู„ู‰ ุงุณุชุฎุฏุงู… HTTP/1.1 ู„ู‚ุชู„ ุงู„ู€ COMPRESSION_ERROR
# ุฅุญู†ุง ุจู†ูƒุฑูŠุช Session ูŠุฏูˆูŠ ูˆู†ู‚ูู„ ููŠู‡ุง ุงู„ู€ http2
sync_client = httpx.Client(
    http2=False, # ุงู„ุฃู…ุงู† ุฃูˆู„ุงู‹
    timeout=60,
    limits=httpx.Limits(max_keepalive_connections=20, max_connections=100) # ๐Ÿ’Ž ุงู„ุญู‚ู†ุฉ ุงู„ู…ุงุณูŠุฉ: ุฎู„ูŠ ุงู„ุฎุท ู…ูุชูˆุญ ุฏุงูŠู…ุงู‹
)

opts = ClientOptions(
    postgrest_client_timeout=60,
    schema="public"
)

# ุฅู†ุดุงุก ุงู„ุนู…ูŠู„ ุงู„ู€ Sync ู…ุน ุงู„ุณูŠุดู† ุงู„ู…ุฎุตุตุฉ
_sync_supabase = create_client(url, key, options=opts)
_sync_supabase.postgrest.session = sync_client # ๐Ÿ‘ˆ ุงู„ุญู‚ู†ุฉ ุงู„ู…ุงุณูŠุฉ ู‡ู†ุง

class _AsyncQuery:
    __slots__ = ('_q',)
    def __init__(self, sync_query): self._q = sync_query
    def __getattr__(self, name):
        attr = getattr(self._q, name)
        if callable(attr):
            def chain(*args, **kwargs): return _AsyncQuery(attr(*args, **kwargs))
            return chain
        return attr
    async def execute(self):
        return await asyncio.to_thread(self._q.execute)

class _AsyncTable:
    def __init__(self, table_name): self._table = table_name
    def __getattr__(self, name):
        sync_method = getattr(_sync_supabase.table(self._table), name)
        def chain(*args, **kwargs): return _AsyncQuery(sync_method(*args, **kwargs))
        return chain

class AsyncSupabaseClient:
    def table(self, name): return _AsyncTable(name)
    def __getattr__(self, name):
        attr = getattr(_sync_supabase, name)
        if callable(attr):
            async def async_wrapper(*args, **kwargs):
                return await asyncio.to_thread(attr, *args, **kwargs)
            return async_wrapper
        return attr

supabase = AsyncSupabaseClient()
print("โœ… [DATABASE] HTTP/1.1 Enforced - Async Wrapper Ready.")