project init and sql outline
This commit is contained in:
parent
f9659e0430
commit
f41d2c2b2c
22 changed files with 287 additions and 1 deletions
36
.gitignore
vendored
Normal file
36
.gitignore
vendored
Normal 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
|
11
README.md
11
README.md
|
@ -1,3 +1,14 @@
|
|||
# klist
|
||||
|
||||
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
107
pom.xml
Normal 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
63
src/main/kotlin/Main.kt
Normal 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")
|
||||
}
|
39
src/main/resources/init.sql
Normal file
39
src/main/resources/init.sql
Normal 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)
|
||||
)
|
1
src/main/resources/prepare/add_list.sql
Normal file
1
src/main/resources/prepare/add_list.sql
Normal file
|
@ -0,0 +1 @@
|
|||
insert into lists values (?1, ?2);
|
1
src/main/resources/prepare/add_list_for_user.sql
Normal file
1
src/main/resources/prepare/add_list_for_user.sql
Normal file
|
@ -0,0 +1 @@
|
|||
insert or ignore into user_lists values (?1, ?2);
|
1
src/main/resources/prepare/add_stage_for_list.sql
Normal file
1
src/main/resources/prepare/add_stage_for_list.sql
Normal file
|
@ -0,0 +1 @@
|
|||
insert into task_stages values (?1, ?2, ?3);
|
1
src/main/resources/prepare/add_task_to_list.sql
Normal file
1
src/main/resources/prepare/add_task_to_list.sql
Normal file
|
@ -0,0 +1 @@
|
|||
insert into tasks values (?1, ?2, ?3);
|
1
src/main/resources/prepare/add_user.sql
Normal file
1
src/main/resources/prepare/add_user.sql
Normal file
|
@ -0,0 +1 @@
|
|||
insert into users values (?1);
|
0
src/main/resources/prepare/cleanup.sql
Normal file
0
src/main/resources/prepare/cleanup.sql
Normal file
0
src/main/resources/prepare/get_list_for_user.sql
Normal file
0
src/main/resources/prepare/get_list_for_user.sql
Normal file
1
src/main/resources/prepare/get_lists.sql
Normal file
1
src/main/resources/prepare/get_lists.sql
Normal file
|
@ -0,0 +1 @@
|
|||
select * from lists;
|
1
src/main/resources/prepare/get_stages_for_list.sql
Normal file
1
src/main/resources/prepare/get_stages_for_list.sql
Normal file
|
@ -0,0 +1 @@
|
|||
select * from task_stages where list_id = ?1;
|
1
src/main/resources/prepare/get_users.sql
Normal file
1
src/main/resources/prepare/get_users.sql
Normal file
|
@ -0,0 +1 @@
|
|||
select * from users;
|
3
src/main/resources/prepare/reg_discord_for_user.sql
Normal file
3
src/main/resources/prepare/reg_discord_for_user.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
update users
|
||||
set discord_id = ?1
|
||||
where id = ?2;
|
3
src/main/resources/prepare/reg_google_for_user.sql
Normal file
3
src/main/resources/prepare/reg_google_for_user.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
update users
|
||||
set google_id = ?1
|
||||
where id = ?2;
|
3
src/main/resources/prepare/reg_local_for_user.sql
Normal file
3
src/main/resources/prepare/reg_local_for_user.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
update users
|
||||
set local_id = ?1
|
||||
where id = ?2;
|
1
src/main/resources/prepare/remove_list_for_user.sql
Normal file
1
src/main/resources/prepare/remove_list_for_user.sql
Normal file
|
@ -0,0 +1 @@
|
|||
delete from user_lists where user_id = ?1 and list_id = ?2;
|
0
src/main/resources/prepare/remove_task.sql
Normal file
0
src/main/resources/prepare/remove_task.sql
Normal file
0
src/main/resources/prepare/remove_user.sql
Normal file
0
src/main/resources/prepare/remove_user.sql
Normal file
12
src/test/kotlin/DatabaseTests.kt
Normal file
12
src/test/kotlin/DatabaseTests.kt
Normal 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);
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue