Together-Java / TjBot

A bot for the together java discord server. Name still undecided
6 stars 6 forks source link

Database setup #9

Open AzatothTheAwakened opened 4 years ago

AzatothTheAwakened commented 4 years ago

As already asked and suggested in #4 there is a need to define what Databse and DB-Accessor will be used. My suggestion would be To use SQLite and JOOQ. SQLite needs almost no setup and thus makes the bot more accessible for newer people. On top of that JOOQ makes the Database exchangable and abstracts raw SQL. Yet JOOQ code is still pretty close to plain SQL which makes it again good for beginners learning SQL.

We definetly need some more feedback on frameworks and libraries. Maybe someone else knows a better combo.

acathers commented 4 years ago

The database really doesn't matter that much, but I would prefer to use Hibernate since it's an in demand skill that is heavily used in Spring. Using hibernate you can use pretty much any database you'd like and setup is minimal.

I-Al-Istannen commented 4 years ago

Hibernate is pretty far from writing SQL. If you want to learn SQL, JOOQ is probably quite a bit better.

It is quite a bit simpler to use hibernate though, so maybe it is better suited for beginners?

If you go the JOOQ route, you can also easily manage the schema with Flyway, with Hibernate that is a bit more fun, if I am not misinformed.

Not quite sure

SeaLife commented 4 years ago

I recommend to use Spring Data JPA

nxtk commented 4 years ago

sqlite and jooq seems like a reasonable choice, just the right amount of complexity to be useful experience for a new contributors aswell, unlike jpa enterprise black magic monstrosity

phydesmith commented 4 years ago

Was there a final decision on how this was going to be implemented? I’d like to learn how the process works.

acathers commented 4 years ago

Was there a final decision on how this was going to be implemented? I’d like to learn how the process works.

Leslie said Thursday would be the decision.

AzatothTheAwakened commented 4 years ago

so 3 people people (including me) voted for jooq. So I think we should go with that, Im sorry to the others.

But please implement any data access as Repository to make the dataaccess (jooq) exchangable. Repositories should be tested. Also extract interfaces from the repositories and work with dependency injection (constructor injection).

thmalek commented 4 years ago

Just found out about this, I may be a little late for the party, but here are my thoughts:

Spring is the industry standard and there is no debate about this, moving the project to Spring would be a huge plus. (but please, no XML BS.. #annotations)

About the database, if you want something portable, H2 is by far the best.. Fully supported by Spring Data/JPA, also, it has an awesome webconsole embedded if the user wants to do stuff more visually.

SeaLife commented 4 years ago

I'm also on the Spring-Train. There are a ton advantages you get by using Spring. But @thmalek i know someone is against Spring because its doing to much "magic".

+1 Spring -1 any other DB-Access methods

AzatothTheAwakened commented 4 years ago

So we want to integrate a huuuge framework just to automate some very basic queries? For example this does not really look like much work: https://github.com/Together-Java/TjBot/blob/72e957ea7a6fd3f938c260677c5bbf1dc1c4ebe1/src/main/java/org/togetherjava/discordbot/db/repositories/ExampleRepository.java

thmalek commented 4 years ago

The thing about Spring is that you won't be only using it for querying the database, there are other features like DI/IOC. Even if you pretend to exclusively do very simple CRUD operations (which is not the case), Spring still a good idea.

Let's suppose that the community grows and now we have 50k members. Dealing with all modmail and reports through discord chat would be a mess, Spring MVC or WebFlux is one dependency away and your current code is already fully compatible.

AzatothTheAwakened commented 4 years ago

Look at this principle: https://clean-code-developer.com/grades/grade-5-blue/#You_Aint_Gonna_Need_It_YAGNI I mean honestly with the Repository Patterns changing it later should not be a problem to integrate it when needed. I'm really having a hard time befriending the idea. Considering the current Issues, there is afaik nothing more than just key value pairs stored in a db. Also this is rather targeted to beginners as an example on how to do some stuff. Spring is too "invisible" to actually show some examples. Current technologies suffice for this.

We got some other project in consideration that would involve Spring for more experienced members.

RicardoMonteiroSimoes commented 4 years ago

Ive got to supply my opinion too, I guess. I am against Spring for the sole reason that it will scare beginners away. Having them see hugely annoted classes or whatever, that, from their point of view, dont make much sense would be a terrible thing. One could, in theory, say the same about jooq. The only difference is that in jooq, the codebase is somewhat readable. If youve ever heard of or seen SQL queries you'll grasp it relatively fast.

BookRecord book = new BookRecord();
 book.setAuthorId(1);
 book.setPublishedIn(1970);
 book.setLanguageId(1); 

// Using the explicit condition() API Result<BookRecord> books1 = DSL.using(configuration) 
.selectFrom(BOOK) 
.where(condition(book)) 
.fetch(); 

// Using the convenience API on DSLContext Result<BookRecord> books2 = DSL.using(configuration)
.fetchByExample(book)

Seems pretty readable to me

RicardoMonteiroSimoes commented 4 years ago

I guess after checking this out: https://www.baeldung.com/spring-jdbc-jdbctemplate

It doesnt seem that far fetched. Also setup seems pretty straight forward - as stated the question should probably rather be what is less overwhelming for new people.

thmalek commented 4 years ago

Look at this principle: https://clean-code-developer.com/grades/grade-5-blue/#You_Aint_Gonna_Need_It_YAGNI

Sure, overthinking and extreme precipitation are bad, but there is no issue in thinking a little ahead to better structure your code to prevent a big refactoring later on.

About readability:

public interface UserRepository extends JpaRepository<User, Long>
{
    List<User> getUserByNameContainsOrNameContains(String s, String t);
} 

Seems really easy to beginners understand what this method will do. If you are not familiar with Spring: Yes, that is the whole thing, a simple interface with the method name "emulating" a SQL, Spring will do the rest.

Also, if you want, you can also write your own SQL.

RicardoMonteiroSimoes commented 4 years ago

I can see your point, sure sure. If the setup is as straightforward as that code snippet then I guess Spring might be okay 🤷‍♂️