memtrip / SQLKing

SQLKing is an Android SQLite ORM powered by an annotation preprocessor, tables are defined by Table annotations and CRUD classes expose an expressive api for executing SQLite queries. @memtrip
Other
21 stars 9 forks source link

How to annotate a column as a Foreign Key and/or Index? #3

Closed Trellian closed 8 years ago

Trellian commented 8 years ago

Hi Sam,

What is the syntax for Foreign Key/Index annotation?

Regards, Adrian

Trellian commented 8 years ago

Not to worry, I figured it out.. (facepalm!)

@Column (index = true, foreign_key = "TblParent")

samkirton commented 8 years ago

hi Adrian,

Although you can use the index / foreign_key labels, they currently do not impose the constraints. I am working on a pull request for this at the moment.

Cheers, Sam

Trellian commented 8 years ago

Thanks Sam! Any ideas on an ETA?

samkirton commented 8 years ago

The end of next week

Trellian commented 8 years ago

Hi Sam,

I'm hoping you have had a chance to work on this? Also, do you have any comments about doing join queries?

Thanks, Adrian

samkirton commented 8 years ago

Hi Adrian,

This will be ready on Monday, I will add to the example and let you know.

Cheers, Sam

Trellian commented 8 years ago

Thanks Sam, looking forward to it :) /Adrian

Trellian commented 8 years ago

Waiting in antici.......pation! :) /Adrian

samkirton commented 8 years ago

Wednesday evening, I promise!

samkirton commented 8 years ago

sorry for the slow progress, I was caught up in other work, you can see the progress in this branch: https://github.com/memtrip/SQLKing/tree/feature/foreign_key_constraints

Trellian commented 8 years ago

No problem, we're all in the same boat :) If I may be so bold as to make a (selfish) suggestion, I don't use composite foreign keys, because I only ever use autoinc id fields for my primary keys. If you would like to work on the join functionality before adding support for composite FK's, I would greatly appreciate it.

Trellian commented 8 years ago

Hi Sam, any news?

samkirton commented 8 years ago

Hi Adrian,

Its close, tonight I will work on a way to make columns unique across joins, currently if I have a "timestamp" on both User and Log tables, the ORM mapper has no way to tell which object to set the column on!

Trellian commented 8 years ago

Hi Sam, any news? Is there anything I can help with? I've been doing a bit of study on using APT, and my SQL is not bad, including writing advanced code-generation of relational and CRUD templates :)

samkirton commented 8 years ago

Hi Adrian,

If you checkout and build the branch named "feature/foreign_key_constraints", you will have INNER JOIN functionality. Please see com.memtrip.sqlking.integration.InnerJoinTest for usage.

Sorry for the delay, its been a busy summer! Going forward some help would be great, SQLProvider.java and ClauseHelper.java classes are a good place to start!

Nested joins are not working yet, I will develop this before making a release to maven central.

Cheers, Sam

samkirton commented 8 years ago

See the "feature/join_annotation" branch, this has more up to date changes.

Trellian commented 8 years ago

Hi Sam,

I can't get the project to build in AS 2.1.2. I get the following error:

Error:Could not find com.memtrip.sqlking:common:1.0.9. Required by: com.memtrip.sqlking:client:1.0.7

even though the poml.xml for the common module says it is 1.0.9. Any ideas?

I also cannot find an example of the foreign key annotation in that branch. Is it required in order to setup for the joins?

Thanks, Adrian

samkirton commented 8 years ago

Hi Adrian,

You need to run mvn clean install on both the common and preprocessor projects to get them into your maven local. There is no need for the foreign key annotation to make a join, I will add this to the example and make a real release next week.

Cheers, Sam

Trellian commented 8 years ago

Thanks Sam, that worked. However, I can't figure out how to get the 1.0.7 client into my project. I have tried importing it, but it doesn't work. What's the trick?

Thanks, Adrian

samkirton commented 8 years ago

Hi Adrian,

The new version has been released, if you check the README it has the updated versions (1.1).

gradle install on the client directory and mavenLocal() in your build.gradle would have worked locally though.

Cheers, Sam

samkirton commented 8 years ago

Also I added a inner join example to the sample project.

Cheers, Sam