Giter Club home page Giter Club logo

Comments (5)

rbock avatar rbock commented on July 22, 2024

Hi Thomas,

You did not miss it. There is no such mechanism yet.

I'll think about it. If you have suggestions for the syntax, please let
me know. There is also the question of how much type-safety is required
here? Should we define the database of the table in the header? Probably
not.

BTW: I think I am getting closer to the custom/patchwork query.

Regards,

Roland

On 2014-10-16 21:34, Thomas marsh wrote:

Hi Roland,

Perhaps I missed it while browsing the code, but is there a way to
specify the database in a query? I need to work with multiple
databases (e.g., via |ATTACH| in SQLite), and I am unable to perform
operations outside of the |main| (default) database. E.g., I perform
the following:

|ATTACH 'a.db' AS a;
ATTACH 'b.db' AS b;
SELECT t1.foo, t2.bar FROM a.my_table AS t1, b.my_table AS t2 WHERE t1.id = t2.id;
|

Currently, I'm unaware of a mechanism to provide such queries in a
type-safe manner.


Reply to this email directly or view it on GitHub
#19.

from sqlpp11.

thomasmarsh avatar thomasmarsh commented on July 22, 2024

I'm not sure about the best syntax. It should be in the from clause (or near to it) and seems like it would be natural as a method on the table instance or as a decorator. In the SQL:2011 standard grammar, the portion before the dot in a table name (e.g., the "a" in SELECT foo FROM a.my_table) is called the "schema qualifier". So, one usage pattern might be:

auto a_t = sqlpp::schema_qualified("a", MyTable());

select(a_t.foo).from(a_t).where(true);

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

That is certainly reasonable enough to start with. The calling "ATTACH"
via db.exectute() would be the developer's responsibility, right?

It should be relatively easy to do this similar to using select
statements as tables.

Best,

Roland

from sqlpp11.

thomasmarsh avatar thomasmarsh commented on July 22, 2024

Yes, I anticipated calling ATTACH via db.execute() since it is a database specific extension and not part of the SQL standard.

P.S. I'm looking forward to patchwork! Exciting that it's coming along.

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

Hi Thomas,

I finally got to this one. You can now do

  sql::connection_config config;
  config.path_to_database = ":memory:";
  auto other = db.attach(config, "other");
  auto right = schema_qualified_table(other, TabSample{}).as(sqlpp::alias::right);

right then evaluates to other.tab_sample.

The attach method is currently implemented for the sqlite connector only.

Cheers,

Roland

from sqlpp11.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.