I have a project that uses the Couchbase python SDK.
And I recursively make connections to the cluster. My connection file is something like:
from couchbase.cluster import Cluster, ClusterOptions
#from couchbase_core.cluster import PasswordAuthenticator
from couchbase.auth import PasswordAuthenticator
# needed for options -- cluster, timeout, SQL++ (N1QL) query, etc.
from couchbase.options import (ClusterOptions)
def conexion():
# especifique el clúster y especifique un autenticador que contenga un nombre de usuario
# y una contraseña para pasar al clúster.
cluster = Cluster('couchbase://0.0.0.0.0', ClusterOptions(PasswordAuthenticator('user', 'userPasw')))
return cluster
I have several files with that connection code for each entity, for example: (room, window, services, offices, etc.), and I consult it by opening several connections to the database per query.
Is this practice well done?
Should I have a single connection file?
Should a single connection be opened for n number of queries?