Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Database setup #9

Open
AzatothTheAwakened opened this issue Jan 5, 2020 · 16 comments
Open

Database setup #9

AzatothTheAwakened opened this issue Jan 5, 2020 · 16 comments
Labels
discussion Discussion about the direction the project is about to go

Comments

@AzatothTheAwakened
Copy link
Member

AzatothTheAwakened commented Jan 5, 2020

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.

@AzatothTheAwakened AzatothTheAwakened added the discussion Discussion about the direction the project is about to go label Jan 5, 2020
@acathers
Copy link

acathers commented Jan 5, 2020

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
Copy link
Collaborator

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
Copy link

SeaLife commented Jan 5, 2020

I recommend to use Spring Data JPA

@nxtk
Copy link

nxtk commented Jan 14, 2020

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
Copy link

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

@acathers
Copy link

acathers commented Jan 16, 2020

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
Copy link
Member Author

AzatothTheAwakened commented Jan 16, 2020

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).

acathers added a commit to acathers/TjBot that referenced this issue Jan 18, 2020
acathers added a commit to acathers/TjBot that referenced this issue Jan 18, 2020
@thmalek
Copy link

thmalek commented Jan 19, 2020

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
Copy link

SeaLife commented Jan 20, 2020

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
Copy link
Member Author

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
Copy link

thmalek commented Jan 21, 2020

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.

acathers added a commit to acathers/TjBot that referenced this issue Jan 21, 2020
acathers added a commit to acathers/TjBot that referenced this issue Jan 21, 2020
acathers added a commit to acathers/TjBot that referenced this issue Jan 22, 2020
@AzatothTheAwakened
Copy link
Member Author

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
Copy link

RicardoMonteiroSimoes commented Jan 22, 2020

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
Copy link

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
Copy link

thmalek commented Jan 22, 2020

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
Copy link

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

acathers added a commit to acathers/TjBot that referenced this issue Jan 25, 2020
acathers added a commit to acathers/TjBot that referenced this issue Jan 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
discussion Discussion about the direction the project is about to go
Projects
None yet
Development

No branches or pull requests

8 participants