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

Function to run raw commands #43

Closed
GitHunter0 opened this issue Apr 19, 2022 · 2 comments
Closed

Function to run raw commands #43

GitHunter0 opened this issue Apr 19, 2022 · 2 comments
Assignees
Labels

Comments

@GitHunter0
Copy link

GitHunter0 commented Apr 19, 2022

Hi folks, first let me say nodbi is a really great project that I hope keeps flourishing.

Is there a way to run raw database commands (for operations that nodbi currently does not implement), analogous to mongolite's run()?

I have also 2 aside questions if I may:
(1) How can I disconnect from the database? I could not find in nodbi a command like mongolite's $disconnect()
(2) Since in commands like docdb_query(key = "...") we cannot change the key (we would receive a warning message), why make mandatory to provide it every time? In mongolite, for example, $find() just requires the query paramater.

Thank you

@rfhb rfhb self-assigned this Apr 20, 2022
@rfhb rfhb added the question label Apr 20, 2022
@rfhb
Copy link
Collaborator

rfhb commented Apr 25, 2022

Hi and many thanks, sorry, could not reply earlier.

Are you looking to run a few specific commands across all backends? Which commands are you thinking of? If the command would not have analogous or corresponding commands across the backends, it may be easier to just call the backend-specific function, for example:

dbc <- nodbi::src_mongo(
    db = "my_db", 
    collection = "my_coll")

mongolite::mongo(
  collection = dbc$collection,
  db = dbc$db,
  url = dbc$url)$run(command = '{"ping": 1}')

In analogy, the other backends can be used with a nodbi connection object.

Re (1): manually disconnecting is not necessary for several (e.g. PostgreSQL, MongoDB) if not all backends. A method could be added but R's garbage collection should be sufficient. Did you run into any problems?

Re (2): this is for consistency of the main parameters across nodbi functions. I will review if simplifying the function signature e.g. for nodbi::docdb_query() would be a good gain.

Thanks again

@GitHunter0
Copy link
Author

GitHunter0 commented Apr 26, 2022

Hi @rfhb , thank you for the feedback.

If the command would not have analogous or corresponding commands across the backends,

That's my case, I just thought it would be nice to use one single connection (in this case nodbi) for every possible operation. That being said, the trick of using dbc$... is handy and indeed reduces the hurdle.

(1) I've not run into problems yet, I will stick with the garbage collection solution and see if any issue appears.

(2) Understood.

I also opened this issue in connections package which I believe would be a great fit for nodbi.

Thanks again and congratulations on the project.

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

No branches or pull requests

2 participants