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

Fix for delimiting table-names (and supporting queries covering multi-db or multi-schema) #105

Merged
merged 4 commits into from
Jan 6, 2013

Conversation

tyano
Copy link
Contributor

@tyano tyano commented Jan 6, 2013

This patch is for fixing the way of delimiting table-names. At same time, we can support Postgres' schema and queries covering multiple databases with this patch.

This patch will fix the issue #98 too.

In MySQL, it is very usual that an query use multiple databases like bellow:

SELECT * FROM db1.table1 LEFT JOIN other_db.table2 ON db1.table1.key = other_db.table2.key;

Korma currently don't support this kind of query well, because Korma don't delimit table-names correctly.

Think about a situation where we use multiple database. We probably define entites with db-name like bellow:

(defentity book (table :mydb.book))
(defentity author (table :mydb.book) (belongs-to book))

and query:

(select author (with book))

Korma will generate an query like:

SELECT "mydb.author".*, "mydb.book".* FROM "mydb.role" LEFT JOIN "mydb.book" ON "mydb.book"."id" = "mydb.role"."book_id"

This query doesn't work. We should delimit table-names like bellow:

SELECT "mydb"."author".*, "mydb"."book".* FROM "mydb"."role" LEFT JOIN "mydb"."book" ON "mydb"."book"."id" = "mydb"."role"."book_id"

If korma delimit table-names as above, users of mysql can use multi-db well, and at same time, users of postgres can use schema-name as well.

With my patch, Korma will delimit table-names like the last example.

@AlexBaranosky
Copy link
Member

You should merge master into your fork, so your pull request could be merged.

@tyano
Copy link
Contributor Author

tyano commented Jan 6, 2013

OK, I merged the newest master to my fork and pushed.

AlexBaranosky added a commit that referenced this pull request Jan 6, 2013
Fix for delimiting table-names (and supporting queries covering multi-db or multi-schema)
@AlexBaranosky AlexBaranosky merged commit b880d44 into korma:master Jan 6, 2013
@AlexBaranosky
Copy link
Member

Thanks for your contribution.

AlexBaranosky added a commit that referenced this pull request Jan 6, 2013
@casperc
Copy link

casperc commented Jan 8, 2013

Thanks.

Any chance of creating a (beta)release just for this change? I was pulling my hair out trying to work out why postgres schemas just would not work with Korma.

@AlexBaranosky
Copy link
Member

Sure why not. I'll do it tonight.

@AlexBaranosky
Copy link
Member

Pushed.

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.

3 participants