Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SQLServer_Persister #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hamidmujtaba
Copy link

Baseline SQLServer_Persister Added.
Added useful error messages while resolution of dependencies in order to run it.

Copy link
Contributor

@Kulv3r Kulv3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice persister!
Please fix these minor problems I mentioned and we can merge it.

primary_key=self._primary_key)

@staticmethod
def __check_dependencies():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please look how it's implemented in the other persisters and adjust your code accordingly:
https://github.com/i2mint/py2store/blob/master/py2store/persisters/sql_w_sqlalchemy.py#L3

import pyodbc

if 'ubuntu' in platform.platform().lower():
result = subprocess.Popen(["dpkg", "-s", "msodbcsql17"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will be executed every time you init a new SQLServerPersister instance.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the intended behaviour, As py2store will be used for every storage type, but whenever user wants to use to for the SQLServer and creates an instance of the SQLServerPersister, we should check for dependencies of the SQLServer.

self._cursor.execute(self._select_query.format(value=k))
record = self._cursor.fetchone()
return record if record else print(f"No record found for primary_key: {k}")
# TODO: Raise a proper exception here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please raise KeyError here and below.

.format(conn_protocol, host, port, db_name, db_username, db_pass))

self._cursor = self._sql_server_client.cursor()
self._table_name = table_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make sure this table will be created, if it's not present, so user dont have to worry about it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


class SQLServerPersister(MutableMapping):
def __init__(self, conn_protocol='tcp', host='localhost', port='1433', db_username='SA', db_pass='Admin123x',
db_name='py2store', table_name='person', primary_key='id', data_fields=('name',)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

primary_key might be a tuple of multiple key fields. Persister should be flexible enough to work with such cases.

Also, please rename it to key_fields.

@hamidmujtaba hamidmujtaba force-pushed the master branch 2 times, most recently from 30b2311 to ad02e6e Compare October 5, 2019 09:11
@hamidmujtaba
Copy link
Author

Nice persister!
Please fix these minor problems I mentioned and we can merge it.

Thanks for your kind review @Kulv3r, I've incorporated the changes you suggested. Please take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants