Giter Club home page Giter Club logo

sqlitequerybuilder's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqlitequerybuilder's Issues

Not possible to chain multiple join statements other than regular join

I would like to be able to do the following:

.from("table1")
.leftOuterJoin("table2").on(...)
.leftOuterJoin("table3").on(...)
.where(...)

As far as I understand it is not possible to chain multiple left outer join statements after each other (or any other non-regular join). Any plans to add it?

Chain order by to join

Hi again!

Still this is the best library to easily make sqlite queries, without having a complete orm :).
I still find some things missing, I hope you can add these features. I added the queries I want to build below the list items.

  • COUNT statement

"SELECT COUNT(*) " + "FROM " + MOVIE_TABLE + " " + "WHERE " + MOVIE_ID_TRAKT + "=?";

  • Chain ORDER BY to a JOIN statement

"SELECT " + WATCHLIST_TABLE + ".*, " + "CASE WHEN " + WATCHLIST_TABLE + "." + WATCHLIST_TYPE + "='" + WatchlistItem.TYPE_MOVIE + "' " + "THEN " + MOVIE_TABLE + "." + MOVIE_TITLE + " " + "ELSE " + SHOW_TABLE + "." + SHOW_TITLE + " " + "END AS watchlist_item_title, " + "CASE WHEN " + WATCHLIST_TABLE + "." + WATCHLIST_TYPE + "='" + WatchlistItem.TYPE_SEASON + "' " + "THEN " + SEASON_TABLE + "." + SEASON_NUMBER + " " + "WHEN " + WATCHLIST_TABLE + "." + WATCHLIST_TYPE + "='" + WatchlistItem.TYPE_EPISODE + "' " + "THEN " + EPISODE_TABLE + "." + EPISODE_SEASON + " " + "ELSE NULL " + "END AS season_number," + EPISODE_TABLE + "." + EPISODE_NUMBER + " AS episode_number " + "FROM " + WATCHLIST_TABLE + " " + "LEFT JOIN " + MOVIE_TABLE + " " + "ON " + WATCHLIST_TABLE + "." + WATCHLIST_MOVIE_ID + "=" + MOVIE_TABLE + "." + MOVIE_ID_TRAKT + " " + "LEFT JOIN " + SHOW_TABLE + " " + "ON " + WATCHLIST_TABLE + "." + WATCHLIST_SHOW_ID + "=" + SHOW_TABLE + "." + SHOW_ID_TRAKT + " " + "LEFT JOIN " + SEASON_TABLE + " " + "ON " + WATCHLIST_TABLE + "." + WATCHLIST_SEASON_ID + "=" + SEASON_TABLE + "." + SEASON_ID_TRAKT + " " + "LEFT JOIN " + EPISODE_TABLE + " " + "ON " + WATCHLIST_TABLE + "." + WATCHLIST_EPISODE_ID + "=" + EPISODE_TABLE + "." + EPISODE_ID_TRAKT + " " + "ORDER BY " + "CASE WHEN LOWER(SUBSTR(watchlist_item_title,1,4)) = 'the ' " + "THEN SUBSTR(watchlist_item_title,5) ELSE watchlist_item_title END ASC, " + "season_number ASC, episode_number ASC";

  • Also I am kind of using prepared statements with '=?' but it would be nice, not to have to write this all the time. Though I would understand it if this is something that was not intended for the query builder.

Thanks in advance!

Can't provide auto increment primary key

if i do something like this
SQLiteQueryBuilder.create().table(Constants.TBL_RECENT).column(new Column("demo", ColumnType.TEXT)).column(new Column("demo1", ColumnType.INTEGER)).column(new Column("pk", ColumnType.INTEGER, ColumnConstraint.PRIMARY_KEY)).toString()
out put will be
CREATE TABLE recent(demo TEXT,demo1 INTEGER,pk INTEGER PRIMARY KEY)

but what if i want to do some thing like this
CREATE TABLE recent(demo TEXT,demo1 INTEGER,pk INTEGER PRIMARY KEY) AUTOINCREMENT

COUNT statement

Hi,

I posted another issue #48 where you asked me to split my features in different issues, so this is the first one.

I wonder if you could find a way to easily make a select count statement like below :).

"SELECT COUNT(*) " + "FROM " + MOVIE_TABLE + " " + "WHERE " + MOVIE_ID_TRAKT + "=?";

Cannot call limit after where

Should be able to do something like....

String sql = SQLiteQueryBuilder
  .select("*")
  .from("users")
  .limit(10)
  .build()

Foreign keys

Would it be possible to create a feature to create foreign keys to other tables?

Add argument checks and fail early

In each builder, we should have some sort of argument check, like this.

Errors should be caught and thrown as early as possible. If, for example, these checks were done right before the build() function was called, it would be extremely hard to debug since the stack trace would only point to the toString()/build() line and not where the actual error happened.

Improve statement string builder

Currently statements are built by using a series of append operations on StringBuilder. This is not exactly ideal since it is very vulnerable to bugs and mistakes. Look into a better, safer method.

Support for other Join operators

Basically:

  • (natural) left outer join
  • cross join

For the API we can use the same approach like JOOQ uses:

leftOuterJoin("secondtable")
naturalJoin("table")
naturalLeftOuterJoin("table")
crossJoin("secondtable")

I can create a PR for this if you want, i'll be happy to contribute.

Prepared statements

Hi,

It would also be nice if I can mark a select query as a prepared statement so that I do not have to write "=?" everytime. I understand it though if this is a feature that is out of scope in this library.

Use package-private scope

We should consider changing some classes scope from public to package private.
This avoids exposing a lot of internal classes that aren't meant to be used outside of the API.

Some examples:

  • JoinType
  • StringUtils

The only troublesome part is that we need to move the tests accordingly to have access to the classes like .StringUtilsTest.java -> .utils.StringUtilsTest.java.

Support DEFAULT

Add support for default values in create table statements.

Use AssertJ for assertions

Replace usage of JUnits assertion statements with AssertJ. AssertJ offers a more fluent and easy to understand API.

Chain order by to join

Hi,

I am executing the very complex query at the end of this issue :P. The only problem with it is that I cannot chain multiple left joins. But also I cannot chain an order by to these join statements.

It would be nice if you could build this feature for me :).

"SELECT " + WATCHLIST_TABLE + ".*, " + "CASE WHEN " + WATCHLIST_TABLE + "." + WATCHLIST_TYPE + "='" + WatchlistItem.TYPE_MOVIE + "' " + "THEN " + MOVIE_TABLE + "." + MOVIE_TITLE + " " + "ELSE " + SHOW_TABLE + "." + SHOW_TITLE + " " + "END AS watchlist_item_title, " + "CASE WHEN " + WATCHLIST_TABLE + "." + WATCHLIST_TYPE + "='" + WatchlistItem.TYPE_SEASON + "' " + "THEN " + SEASON_TABLE + "." + SEASON_NUMBER + " " + "WHEN " + WATCHLIST_TABLE + "." + WATCHLIST_TYPE + "='" + WatchlistItem.TYPE_EPISODE + "' " + "THEN " + EPISODE_TABLE + "." + EPISODE_SEASON + " " + "ELSE NULL " + "END AS season_number," + EPISODE_TABLE + "." + EPISODE_NUMBER + " AS episode_number " + "FROM " + WATCHLIST_TABLE + " " + "LEFT JOIN " + MOVIE_TABLE + " " + "ON " + WATCHLIST_TABLE + "." + WATCHLIST_MOVIE_ID + "=" + MOVIE_TABLE + "." + MOVIE_ID_TRAKT + " " + "LEFT JOIN " + SHOW_TABLE + " " + "ON " + WATCHLIST_TABLE + "." + WATCHLIST_SHOW_ID + "=" + SHOW_TABLE + "." + SHOW_ID_TRAKT + " " + "LEFT JOIN " + SEASON_TABLE + " " + "ON " + WATCHLIST_TABLE + "." + WATCHLIST_SEASON_ID + "=" + SEASON_TABLE + "." + SEASON_ID_TRAKT + " " + "LEFT JOIN " + EPISODE_TABLE + " " + "ON " + WATCHLIST_TABLE + "." + WATCHLIST_EPISODE_ID + "=" + EPISODE_TABLE + "." + EPISODE_ID_TRAKT + " " + "ORDER BY " + "CASE WHEN LOWER(SUBSTR(watchlist_item_title,1,4)) = 'the ' " + "THEN SUBSTR(watchlist_item_title,5) ELSE watchlist_item_title END ASC, " + "season_number ASC, episode_number ASC";

Add checkstyle

As more people contribute, we should all follow the same coding style in order to stay consistent.

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.