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

#9 Database setup #11

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Conversation

acathers
Copy link

Created the initial database with a simple repository system.

import org.jooq.impl.DSL;
import org.togetherjava.discordbot.commands.CommandContext;

public abstract class SimpleRepository<T> implements Repository<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this klass seems to be a baseclass of Jooq implementations. I'd rename this class so that the name reflects what this class represents.

@@ -3,6 +3,8 @@
# The command prefixes
prefixes: ["!", "?"]
botToken: "your token"
# the url for the database connection
dburl: "jdbc:sqlite:yourfile.sqlite"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enter the same db url as in the pom. Since it did not seem to work with 2 different urls.


@ActiveCommand(name = "example", parentClass = BasePrefixCommand.class)
@SuppressWarnings("unused")
public class ExampleCommandDB extends CommandNode<CommandContext> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that you want to show how it works but this command should be disabled in the actual bot. It could lead to people abusing it and trying to fill the server harddrive unecessary.

Comment on lines +84 to +100
### Database Access
1. Create a schema in resources/db, be sure to start it with a correct version number i.e. V1__example
```sqlite
CREATE TABLE IF NOT EXISTS EXAMPLE
(
ID INTEGER AUTO_INCREMENT PRIMARY KEY,
MEMBER varchar(30) NOT NULL,
TEXT varchar(30) NOT NULL
);
```
2. Make a new class in org.togetherjava.db.repositories that extends JooqRepository.
3. Create a Constructor that accepts CommandContext as a parameter.
4. You can then either create a DAO instance using Jooqs generated DAO class that is generated from your schema using
the DSLContext for configuration provided in the JooqRepository class. Or you can directly use the DSLContext to create SQL queries
```java
ExampleDao dao = new ExampleDao(dslContext.configuration());
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems good, but I do not use databases enough to understand some of this terminology. Could someone else review this and confirm it makes sense. @AzatothTheAwakened can you take a look? Would be nice to finish up this PR and get it merged!

@SizableShrimp SizableShrimp added documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed labels Feb 7, 2020
@I-Al-Istannen
Copy link
Collaborator

A JOOQ Db sounds nice. We now also have some DI container that can keep track of it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants