-
Notifications
You must be signed in to change notification settings - Fork 101
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
Connecting to a SQLite/PostgreSQL database in a script #34
Comments
Hi, |
Hi, |
Hi @RAbraham ! I've added an example of running a predicate on SQLite engine: Let me know if it covers your usecase. If you do have time, adding a similar (tested 😄) example for Postgres would be great. Thank you! |
Thanks!
|
To pass a custom database file name use flags. For instance the script above would look like:
And when calling use logica_lib.RunPredicateToPandas(
'sibling_script.l',
'PersonInfo',
user_flags={'database_file': 'my_custom_file.db') At the moment it's not possible to pass a custom connection. Let me know if you have further questions. |
Great, I'll attempt it now and let you know. Thank you very much! |
I'm trying to test this. How do I populate rows in the database from logica? According to the tutorial, I hacked this but I'm missing a concept or two
Error:
|
I got this to work(removed the
|
Great questions!
If you write
You can attach more then one database with @AttachDatabase command. And there can be only one default dataset. Here we pass the same value because we are attaching this database as Your original program complains that db.Person is undefined, which is true. Let me know if you have further questions! |
re: postgres, I did what you said and it works 👍 from logica.common import logica_lib
from sqlalchemy import create_engine
engine = create_engine('postgresql+psycopg2://postgres:somepwd@localhost', pool_recycle=3600)
connection = engine.connect()
result = logica_lib.RunPredicateToPandas(
'/home/rajiv/Documents/dev/python/mercylog/logica/primes_postgresql.l',
'Prime',
connection=connection)
print(result) It was a simple change of just adding
The one thing I found odd is that I had to install |
wow, In In the e.g. above from chartio, the database is I think SQLite has no schema concept and maybe what you are referring to maps more to SQLite(and BigQuery?) |
@RAbraham , oh I see. Then I think I didn't use the word "schema" correctly in my last reply. Yes, it appears that in SQLite schema and database are synonyms while in PostgreSQL they are not. But I am not 100% sure :-) Logica compiler builds SQL as a string. So the Hope this helps and at least it's clear how to use it :-) Let me know! Great to hear it works with PostgreSQL. I think CoLab has psycopg2, so we didn't have to install it there. If you happen to have a chance to send a pull request with your change enabling PSQL and your example of using it (which could have a comment on what needs to be installed) in the examples/more folder, I'd appreciate it! Thank you! |
re: prefix append, nice. reminds me of the Law of Demeter but for network paths :) PR: #204 |
Law of Demeter is an interesting analogy. :-) |
Logica is a wonderful alternative to SQL, and I would like to connect to SQLite/PostgreSQL database in a
l
script for data query. However currently there seems to be limited support for this.Connection to a SQLite database file seems to have been already implemented but has gone undocumented. We could use the
@AttachDatabase
annotation:and then run this script in local command line. But this usage does not appear anywhere in the tutorial and examples.
We have an example of connecting to a PosgreSQL database in
ipynb
files with the help ofsqlalchemy
library:which is great, but I'm not sure if this is possible in a script program.
The text was updated successfully, but these errors were encountered: