1
"""
2
A factory for Database sockets
3
"""
4

5

6 8
def storage_socket_factory(uri, project_name="", logger=None, db_type=None, **kwargs):
7
    """
8
    Factory for generating storage sockets. Spins up a given storage layer on request given common inputs.
9

10
    Right now only supports MongoDB.
11

12
    Parameters
13
    ----------
14
    uri : string
15
        A URI to given database such as ("postgresql://localhost:5432", )
16
    project_name : string
17
        Name of the project
18
    logger : logging.Logger, Optional, Default: None
19
        Specific logger to report to
20
    db_type : string, Optional, Default: 'sqlalchemy'
21
        socket type, 'sqlalchemy'
22
    **kwargs
23
        Additional keyword arguments to pass to the storage constructor
24

25
    Returns
26
    -------
27

28
    """
29

30 8
    if db_type is None:
31
        # try to find db_type from uri
32 8
        if uri.startswith("postgresql"):
33 8
            db_type = "sqlalchemy"
34
        else:
35 0
            raise TypeError("Unknown DB type, uri: {}".format(uri))
36

37 8
    if db_type == "sqlalchemy":
38 8
        from . import sqlalchemy_socket
39

40 8
        return sqlalchemy_socket.SQLAlchemySocket(uri, project=project_name, logger=logger, **kwargs)
41
    else:
42 0
        raise KeyError("DBType {} not understood".format(db_type))

Read our documentation on viewing source code .

Loading