project init and sql outline

This commit is contained in:
theBreadCompany 2025-06-01 06:58:09 +02:00
parent f9659e0430
commit f41d2c2b2c
22 changed files with 287 additions and 1 deletions

36
.gitignore vendored Normal file
View file

@ -0,0 +1,36 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
*.sqlite
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View file

@ -1,3 +1,14 @@
# klist
todos for your browser and terminal
todos for your browser and terminal
## disclaimer
work in progress, very far from production ready. use with caution and mind the [LICENSE](license) file
also, if you're getting mad at me because i used kotlin, i can assure you i will probably will be mad at myself
as well soon enough. there are languages way better for this.
## description
This project aims to provide a CLI as well as a BFF to organize your day-to-day life, even with friends and colleagues.

107
pom.xml Normal file
View file

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dev.thebread</groupId>
<artifactId>klist</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.jvmTarget>9</kotlin.compiler.jvmTarget>
</properties>
<repositories>
<repository>
<id>mavenCentral</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
</repositories>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>2.1.20</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.3</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.3</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>MainKt</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>2.1.20</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>2.1.20</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jetbrains.kotlinx/dataframe
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>dataframe</artifactId>
<version>0.8.0-dev-339-0.10.1.10</version>
<scope>runtime</scope>
</dependency>-->
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.49.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-cli-jvm -->
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-cli-jvm</artifactId>
<version>0.3.6</version>
</dependency>
</dependencies>
</project>

63
src/main/kotlin/Main.kt Normal file
View file

@ -0,0 +1,63 @@
package dev.thebread
import java.sql.DriverManager
import java.sql.Connection
import java.io.File
import java.sql.PreparedStatement
class KlistApp {
enum class PreparedStatementCase {
GET_USERS, GET_LIST_FOR_USER, GET_LISTS, GET_STAGES_FOR_LIST,
ADD_LIST, ADD_USER, ADD_LIST_FOR_USER, ADD_STAGE_FOR_LIST, ADD_TASK_TO_LIST,
MOVE_TASK_TO_STAGE,
REMOVE_TASK, REMOVE_USER, REMOVE_LIST_FOR_USER,
REG_LOCAL_FOR_USER, REG_DISCORD_FOR_USER, REG_GOOGLE_FOR_USER,
CLEANUP,
}
private var conn: Connection
private var stmts: Map<PreparedStatementCase, PreparedStatement>
constructor(path: String?) {
conn = DriverManager.getConnection(if (!path.isNullOrBlank()) path else "jdbc:sqlite::memory:")
dbSetup(conn)
stmts = dbPrepare(conn)
}
private fun dbSetup(conn: Connection) {
val initSql = File("init.sql").readText()
conn.createStatement().executeUpdate(initSql)
}
private fun dbPrepare(conn: Connection): Map<PreparedStatementCase, PreparedStatement> {
return PreparedStatementCase.entries.associateWith { case ->
conn.prepareStatement(
File(
"prepare/${
case.toString().lowercase()
}.sql"
).readText()
)
}
}
private fun assureUser() {}
private fun assureListForUser() {}
private fun assureStageForList() {}
fun createTask() {}
fun moveTask() {}
fun deleteTask() {}
fun createStage() {}
fun moveStage() {}
fun deleteStage() {}
fun deleteUser() {}
}
fun main() {
val app = KlistApp(null);
println("Works yay")
}

View file

@ -0,0 +1,39 @@
create table if not exists users (
id integer primary key,
name text not null,
local_id integer, -- if the thing is running locally
discord_id integer, -- if logging in via web via discord
google_id integer -- if logging in via web via google
);
create table if not exists user_lists (
id integer primary key,
user_id integer not null,
list_id integer not null
);
create table if not exists lists (
id integer primary key,
name text not null,
desc text
);
create table if not exists task_stages (
id integer primary key,
name text not null,
desc text,
list_id integer not null,
foreign key (list_id) references lists(id)
);
-- this currently enables moving tasks _between lists_ (calculated of course)
create table if not exists tasks (
id integer primary key,
name text not null,
desc text,
stage integer not null,
due date,
due_stage integer, -- more like target stage
foreign key (stage) references task_stages(id),
foreign key (due_stage) references task_stages(id)
)

View file

@ -0,0 +1 @@
insert into lists values (?1, ?2);

View file

@ -0,0 +1 @@
insert or ignore into user_lists values (?1, ?2);

View file

@ -0,0 +1 @@
insert into task_stages values (?1, ?2, ?3);

View file

@ -0,0 +1 @@
insert into tasks values (?1, ?2, ?3);

View file

@ -0,0 +1 @@
insert into users values (?1);

View file

View file

@ -0,0 +1 @@
select * from lists;

View file

@ -0,0 +1 @@
select * from task_stages where list_id = ?1;

View file

@ -0,0 +1 @@
select * from users;

View file

@ -0,0 +1,3 @@
update users
set discord_id = ?1
where id = ?2;

View file

@ -0,0 +1,3 @@
update users
set google_id = ?1
where id = ?2;

View file

@ -0,0 +1,3 @@
update users
set local_id = ?1
where id = ?2;

View file

@ -0,0 +1 @@
delete from user_lists where user_id = ?1 and list_id = ?2;

View file

@ -0,0 +1,12 @@
import org.junit.jupiter.api.*;
import dev.thebread.KlistApp;
import org.junit.jupiter.api.Test;
import java.sql.Connection;
class DatabaseTests {
private val app : KlistApp = KlistApp(null);
}