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

Support database specific extensions #25

Open
irar2 opened this issue Dec 5, 2016 · 4 comments
Open

Support database specific extensions #25

irar2 opened this issue Dec 5, 2016 · 4 comments

Comments

@irar2
Copy link
Contributor

irar2 commented Dec 5, 2016

There are several keywords supported by Swift-Kuery that are not supported by some databases. At the moment we are aware of the following:

keyword PostgreSQL SQLite MySQL DB2
RETURNING yes no no no
ANY (subquery) yes no yes
OFFSET without LIMIT yes no no
FULL JOIN yes no no
RIGHT JOIN yes no yes

We propose to deal with each problem in a different way, because we are trying to find a trade-off between supporting as much as possible and still keeping Swift-Kuery reasonable:

  • RETURNING - remove the current support. Allow RETURNING using raw, i.e. add raw(String) method to Insert and Update that will append the contents of the String to the query
  • ANY - add a flag to QueryBuilder to indicate if ANY is supported, and throw an error during build of a query with ANY if it is not
  • OFFSET - don't allow OFFSET without LIMIT
  • JOINs - allow raw type of JOIN in Join enumeration

It is also possible to insert queries in raw queries, for example to support RETURNING in DB2:

let insert = Insert(...)
let insertDescription = connection.descriptionOf(insert)
let rawQuery = "SELECT * FROM FINAL table (\insertDescription)"
connection.execute(rawQuery) 
@ianpartridge
Copy link
Contributor

I think this is a good approach. I'll carry on raising SQLite issues as I find them. We can close them in future.

irar2 added a commit that referenced this issue Dec 21, 2016
irar2 added a commit that referenced this issue Dec 21, 2016
irar2 added a commit that referenced this issue Dec 21, 2016
irar2 added a commit that referenced this issue Dec 21, 2016
irar2 added a commit that referenced this issue Dec 21, 2016
irar2 added a commit that referenced this issue Dec 21, 2016
* #25 Replace RETURNING with raw.

* #25 Check if ANY and ALL are supported.

* #25 Don't allow offset without limit

* #25 Leave JOINs supported by all databases, add rawJoin for the rest

* #25 Review comments. More tests.

* #25 Create subdirectory in Sources
irar2 added a commit that referenced this issue Dec 22, 2016
irar2 added a commit to Kitura/Swift-Kuery-PostgreSQL that referenced this issue Dec 22, 2016
irar2 added a commit that referenced this issue Jan 2, 2017
irar2 added a commit to Kitura/Swift-Kuery-PostgreSQL that referenced this issue Jan 2, 2017
@naithar
Copy link
Contributor

naithar commented Jan 27, 2017

@irar2 as mentioned in #52 and this comment: link, I'll move extension discussions to this issue, so there is no multiple issues for the same feature.

In this commit i've implemented an initial implementation of Extensions.

However, we are not sure your injection points are sufficient

Does injection points mean Position that is used by Extendable protocol? It's designed to be query independent, so for every query the Position should be different.

and also the use of priorities in case of several extensions at the same position worries us.

Doest it mean that there should be no multiple extensions on the same position or that usage of priorities could be error prone if not used correctly?

@irar2
Copy link
Contributor Author

irar2 commented Jan 29, 2017

Hi @naithar,

Yes, by injection points I meant Position, and in my opinion Position is not flexible enough, it defines 5 points (for Select), and we prefer something more universal.

We think that priorities are error prone in this case.

@naithar
Copy link
Contributor

naithar commented Jan 30, 2017

@irar2
String's Range could also be used for injection. The building of a query should probably be changed for this to work, since extension should receive parts of query which in SELECT's case is SELECT, FROM, WHERE and the others. It also should be aware of other extensions that is currently applied to the query to not cause any errors.
The extesion's build method could probably be like:

func injectExtension(into queryParts: [String]) -> [String]

or

func injectExtension(into query: String, to: Range) -> String

Priorities was designed to work with Position atm, so it won't be needed if we find a way to inject extension without it.

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

No branches or pull requests

3 participants