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

neat way to pass a query #79

Closed
dimzon opened this issue Apr 7, 2014 · 15 comments
Closed

neat way to pass a query #79

dimzon opened this issue Apr 7, 2014 · 15 comments

Comments

@dimzon
Copy link
Contributor

dimzon commented Apr 7, 2014

https://github.com/EtnaSoftwareSystems/ormia

// MyDAO.java
public interface MyDAO {
  @Select("SELECT * FROM person WHERE id = ?)
  Person getPersonById(String id);
}

// MyAPP.java
public class MyAPP {
  public static void main(String[] args) {
    Person p = ORMia.getData(MyDAO.class).getPersonById("1234");
  }
}

we can implement this in sql2o using already existing infrastructure

@aldenquimby
Copy link
Contributor

I'm personally not a fan of this. I think sql2o is the best lite ORM for java because of its simplicity, lack of code generation, and easy configuration. There are a few other orms that use annotations like these (see our performance tests for examples). I think this lib should stick roughly to its current api

@aldenquimby
Copy link
Contributor

I'm not saying don't add it, just that I don't think it should live in the core sql2o that most people will use. Maybe we could make a separate maven artifact like "org.sql2o.extensions -> sql2o-annotations" that has this functionality

@dimzon
Copy link
Contributor Author

dimzon commented Apr 7, 2014

Sql2o sql2o = new Sql2o(DB_URL, USER, PASS);
MyDAO dao = sql2o.for(MyDAO.class);
Person p = dao.getPersonById("1234");

@aldenquimby
this is just syntax sugar and better way to organize your selects instead of a set of string constants. I propose this as addiction to (not replacement).

@aldenquimby
Copy link
Contributor

Ok I'm cool with adding this as an extension 👍. Maybe part of a 2.1 release. We've got a few things to wrap up for 1.5, then a bunch of refactoring for 2.0.

@aldenquimby aldenquimby added this to the 2.1 milestone Apr 7, 2014
@dimzon
Copy link
Contributor Author

dimzon commented Apr 8, 2014

@aldenquimby
Copy link
Contributor

Interesting. After the 2.0 release we can make an extension artifact for it and you can put that code there. Also I think things may end up getting much more complicated than this. MyBatis supports annotations like this for all sql calls, and from looking at their code, it ends up being a pretty large undertaking.

What would you want to call the package? sql2o-annotations or sql2o-generation or something like that?

@dimzon
Copy link
Contributor Author

dimzon commented Apr 8, 2014

@aldenquimby
the problem - I really like fluid interface pattern. this means i want to write

sql2o.toDAO(DAO.class)

instead of

DAOFactory.toDAO(sql2o, DAO.class)

unfortunally Java doesnt't have sexy 'extensions methods' features like C# so it's impossible to add toDAO method without affectiong sql2o class....

@aaberg
Copy link
Owner

aaberg commented Apr 8, 2014

I support the idea of a sql2o-annotations extension. I would like to keep this out of the core library. We should not introduce any annotations or similar in the core-lib.

When that is said, I really like the concept, and I think it could become an awesome extension!

Other ideas for an 'annotations' extension, is annotations for generating entities (or pojos) through a constructor. Similar to jackson JsonCreator annotation. And maybe support for some JPA-annotations.

But all of this should not be a part of the core library.

@dimzon
Copy link
Contributor Author

dimzon commented Apr 8, 2014

Other ideas for an 'annotations' extension, is annotations for generating entities (or pojos) through a constructor. Similar to jackson JsonCreator annotation. And maybe support for some JPA-annotations.

this can be done via external ResultSetHandlerFactory

@dimzon
Copy link
Contributor Author

dimzon commented Apr 8, 2014

well, how to remove my annotations-related commits from pull request?

@aaberg
Copy link
Owner

aaberg commented Apr 8, 2014

get the commit-id of the commit with:

git log 

You should pick the commit-id below the first commit you would like the remove. I guess the id you are looking for is e9216c1

to remove the commit

git reset e9216c169540b1de5317928bf86a583162acd1cf

This will remove the commit and unstage your changes. It will not remove any code you have written.

If you want to keep the code in another branch, you can create the branch, checkout the branch and commit to the branch.

git branch newBranchName
git checkout newBranchName
git add -A
git commit

To get back to your master-branch

git checkout master

@dimzon
Copy link
Contributor Author

dimzon commented Apr 8, 2014

@aaberg
I'm sorry. All what I need is to reset to state before initial annotations commit (in other well-known CSV systems this is revert feature)

after I perform git reset e9216c169540b1de5317928bf86a583162acd1cf i can't push any changes

dimzon@eee:~/git/sql2o$ git add core/src/main/java/org/sql2o/Query.java
dimzon@eee:~/git/sql2o$ git push
To https://github.com/dimzon/sql2o.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/dimzon/sql2o.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

@aaberg
Copy link
Owner

aaberg commented Apr 8, 2014

That is because git by default won't allow you to push anything that will remove commit from server. You have to force push.

git push --force

Sorry I forgot to mention this before.

@dimzon
Copy link
Contributor Author

dimzon commented Apr 8, 2014

thanx!

2014-04-08 22:55 GMT+04:00 Lars Aaberg notifications@github.com:

That is because git by default won't allow you to push anything that will
remove commit from server. You have to force push.

git push --force

Reply to this email directly or view it on GitHubhttps://github.com//issues/79#issuecomment-39887239
.

@aaberg
Copy link
Owner

aaberg commented Mar 14, 2024

The issue 10 years old. Closing.

@aaberg aaberg closed this as not planned Won't fix, can't repro, duplicate, stale Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants