Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How do you connect to an existing database so that you can query it? There are examples of how you can specify an "engine" which will create a new database and use it as a backend for executing queries but I want to query existing data in an sqlite database.


To connect to a database file use:

  @AttachDatabase("db_prefix", "your_file.db");
  # Then you can query from it:
  Q(..r) :- db_prefix.YourTable(..r);


Thank you. You can't do Q(..r) in sqlite right? That's what I read in the tutorial.


Ah, yes, you're right! Please do:

  # ...
  Q(your_column) :- example_db.YourTable(your_column:);
You can query multiple columns of course. Feel free to start threads in Discussions of the repo with whatever questions you have!


They are very responsive in the repo discussions, just ask questions there.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: