From e773e49e570f5bc382563cf10dc4e782bc8f26bf Mon Sep 17 00:00:00 2001 From: Teletha Date: Tue, 16 Apr 2024 16:29:39 +0900 Subject: [PATCH] progress --- src/main/java/typewriter/query/Query.java | 81 -------------- src/main/java/typewriter/rdb/SQL.java | 6 + src/test/java/typewriter/query/QueryTest.java | 104 ------------------ 3 files changed, 6 insertions(+), 185 deletions(-) delete mode 100644 src/main/java/typewriter/query/Query.java delete mode 100644 src/test/java/typewriter/query/QueryTest.java diff --git a/src/main/java/typewriter/query/Query.java b/src/main/java/typewriter/query/Query.java deleted file mode 100644 index d16988ce..00000000 --- a/src/main/java/typewriter/query/Query.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2023 Nameless Production Committee - * - * Licensed under the MIT License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://opensource.org/licenses/mit-license.php - */ -package typewriter.query; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import typewriter.api.Identifiable; -import typewriter.api.Specifier; - -public class Query { - - private final List select = new ArrayList(); - - /** - * Declare SELECT statement. - * - * @param names - */ - public final void SELECT(Specifier... names) { - SELECT(Stream.of(names).map(Specifier::propertyName).toList()); - } - - /** - * Declare SELECT statement. - * - * @param names - */ - public final void SELECT(String... names) { - SELECT(List.of(names)); - } - - /** - * Declare SELECT statement. - * - * @param names - */ - public final void SELECT(List names) { - select.addAll(names); - } - - /** - * Declare SELECT statement. - * - */ - public final void avg(Specifier specifier) { - - } - - /** - * Test query. - * - * @param query - * @return - */ - public boolean is(String query) { - return query.equals(toString()); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - - // SELECT - builder.append("SELECT ").append(select.stream().collect(Collectors.joining(", "))); - - return builder.toString(); - } -} diff --git a/src/main/java/typewriter/rdb/SQL.java b/src/main/java/typewriter/rdb/SQL.java index b08b4dbe..7f732838 100644 --- a/src/main/java/typewriter/rdb/SQL.java +++ b/src/main/java/typewriter/rdb/SQL.java @@ -302,6 +302,12 @@ public SQL orderBy(Specifier specifier1, boolean ascending1, Specifier< return this; } + public SQL groupBy(String group) { + text.append(" GROUP BY ").append(group); + + return this; + } + /** * Write SELECT statement. * diff --git a/src/test/java/typewriter/query/QueryTest.java b/src/test/java/typewriter/query/QueryTest.java deleted file mode 100644 index 4e493030..00000000 --- a/src/test/java/typewriter/query/QueryTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2023 Nameless Production Committee - * - * Licensed under the MIT License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://opensource.org/licenses/mit-license.php - */ -package typewriter.query; - -import org.junit.jupiter.api.Test; - -import typewriter.api.model.IdentifiableModel; - -public class QueryTest { - - @Test - void selectName() { - Query query = new Query() { - { - SELECT("test"); - } - }; - - assert query.is("SELECT test"); - } - - @Test - void selectNames() { - Query query = new Query() { - { - SELECT("first", "second"); - } - }; - - assert query.is("SELECT first, second"); - } - - @Test - void selectSpecifier() { - Query query = new Query() { - { - SELECT(Person::getName); - } - }; - - assert query.is("SELECT name"); - } - - @Test - void selectSpecifiers() { - Query query = new Query() { - { - SELECT("first", "second"); - } - }; - - assert query.is("SELECT first, second"); - } - - /** - * - */ - static class Person extends IdentifiableModel { - - public String name; - - public int age; - - /** - * Create empty model. - */ - public Person() { - } - - /** - * @param name - * @param age - */ - public Person(String name, int age) { - this.name = name; - this.age = age; - } - - /** - * Get the name property of this {@link Person}. - * - * @return The name property. - */ - public String getName() { - return name; - } - - /** - * Get the age property of this {@link Person}. - * - * @return The age property. - */ - public int getAge() { - return age; - } - } -}