Open thorwhalen opened 4 years ago
Using the "Factory Method Design Pattern" is possible to create connectors(DB,Storage, Etc.) on fly, no mater the type of configuration you need to create the connector, the easy way to solve is whit config file. Is easy to the user have all his connections centralized in one configuration file.
Think like this...
[DATABASE]
USERNAME: root
PASSWORD: p@ssw0rd
HOST: 127.0.0.1
PORT: 5432
DB: my_database
[DATABASE 2]
USERNAME: root
PASSWORD: p@ssw0rd
HOST: 127.0.0.1
PORT: 5432
DB: my_database
[FILES]
STATIC_FOLDER: static
TEMPLATES_FOLDER: templates
instead of
URL: jdbc:mysql://localhost:3306/test?user=root&password=secret
database1 = create_data(url, *someting )
There is a need of making construction of persisters more uniform.
My idea is to have all the "base" persisters have the first two
__init__
arguments beuri
and collection (or resource or feed or template -- not sure of the "best" word).The uri would be rootdir in file systems, or the URI of a mongo collection for mongo, etc. The collection would be the path_template, and we'd need to figure out what it means for other sources.
I'm pretty sure it's a good idea to have
uri
be the first argument, and have that name, for all persisters (baring in mind, practical classmethods should also be included to construct persisters in other common ways too).I'm not sure of the second argument though, or if it should even be consistent over all persisters. Perhaps this "collection" part can be persister-dependent and be included in the query part of the uri.
References
https://en.wikipedia.org/wiki/URL https://www.python.org/dev/peps/pep-0249/ https://tools.ietf.org/html/rfc6570 (more recent than https://tools.ietf.org/html/rfc3986) https://docs.python.org/3/library/urllib.parse.html (python builtin for parsing)
I'd like base and core py2store stuff to be without external dependencies (if we can avoid it without too much overhead). That said, here are a few external packages, for inspiration/education: https://pypi.org/project/uri/ https://github.com/gruns/furl https://pypi.org/project/uritools/