improve SQL formatting (I guess?)

This commit is contained in:
MiniDigger 2020-07-29 18:24:54 +02:00
parent 53e3a0a154
commit 6c5958e942
3 changed files with 19 additions and 5 deletions

View File

@ -17,12 +17,19 @@ import java.util.List;
@RegisterBeanMapper(ProjectsTable.class)
public interface ProjectDao {
@SqlUpdate("insert into projects (created_at, plugin_id, name, slug, owner_name, owner_id, category, description, visibility) values (:now, :pluginId, :name, :slug, :ownerName,:ownerId, :category, :description, :visibility)")
@SqlUpdate("insert into projects (created_at, plugin_id, name, slug, owner_name, owner_id, category, description, visibility) " +
"values (:now, :pluginId, :name, :slug, :ownerName,:ownerId, :category, :description, :visibility)")
@Timestamped
@GetGeneratedKeys
ProjectsTable insert(@BindBean ProjectsTable project);
@SqlQuery("SELECT CASE WHEN owner_id = :ownerId AND name = :name THEN 'OWNER_NAME' WHEN owner_id = :ownerId AND slug = :slug THEN 'OWNER_SLUG' WHEN plugin_id = :pluginId THEN 'PLUGIN_ID' END FROM projects")
@SqlQuery("SELECT CASE " +
"WHEN owner_id = :ownerId AND name = :name THEN 'OWNER_NAME' " +
"WHEN owner_id = :ownerId AND slug = :slug THEN 'OWNER_SLUG' " +
"WHEN plugin_id = :pluginId THEN 'PLUGIN_ID' " +
"END " +
"FROM projects"
)
InvalidProjectReason checkValidProject(long ownerId, String pluginId, String name, String slug);
@SqlQuery("select * from projects where lower(owner_name) = lower(:author) AND lower(slug) = lower(:slug)")
@ -38,6 +45,11 @@ public interface ProjectDao {
List<ProjectsTable> getProjectsByUserId(long id);
@RegisterBeanMapper(ProjectStatsAll.class)
@SqlQuery("SELECT * FROM (SELECT COUNT(*) as watchers FROM project_watchers pw WHERE pw.project_id = :id) as w, (SELECT COUNT(*) as stars FROM project_stars ps WHERE ps.project_id = :id) as s, (SELECT COUNT(*) as views FROM project_views_individual pvi WHERE pvi.project_id = :id) as v, (SELECT COUNT(*) as downloads FROM project_versions_downloads_individual pvdi WHERE pvdi.project_id = :id) as d")
@SqlQuery("SELECT * FROM " +
"(SELECT COUNT(*) as watchers FROM project_watchers pw WHERE pw.project_id = :id) as w, " +
"(SELECT COUNT(*) as stars FROM project_stars ps WHERE ps.project_id = :id) as s, " +
"(SELECT COUNT(*) as views FROM project_views_individual pvi WHERE pvi.project_id = :id) as v, " +
"(SELECT COUNT(*) as downloads FROM project_versions_downloads_individual pvdi WHERE pvdi.project_id = :id) as d"
)
ProjectStatsAll getProjectStats(long id);
}

View File

@ -20,7 +20,8 @@ import me.minidigger.hangar.model.viewhelpers.Staff;
@RegisterBeanMapper(UsersTable.class)
public interface UserDao {
@SqlUpdate("insert into users (id, created_at, full_name, name, email, tagline, join_date, read_prompts, is_locked, language) values (:id, :now, :fullName, :name, :email, :tagline, :now, :readPrompts, :isLocked, :language)")
@SqlUpdate("insert into users (id, created_at, full_name, name, email, tagline, join_date, read_prompts, is_locked, language) " +
"values (:id, :now, :fullName, :name, :email, :tagline, :now, :readPrompts, :isLocked, :language)")
@Timestamped
@GetGeneratedKeys
UsersTable insert(@BindBean UsersTable user);

View File

@ -16,7 +16,8 @@ public interface UserProjectRolesDao {
@SqlQuery("SELECT * FROM user_project_roles WHERE project_id = :projectId AND user_id = :userId")
UserProjectRolesTable getByProjectAndUser(long projectId, long userId);
@SqlUpdate("INSERT INTO user_project_roles (created_at, user_id, role_type, project_id, is_accepted) VALUES (:now, :userId, :roleType, :projectId, :isAccepted)")
@SqlUpdate("INSERT INTO user_project_roles (created_at, user_id, role_type, project_id, is_accepted) " +
"VALUES (:now, :userId, :roleType, :projectId, :isAccepted)")
@Timestamped
void insert(@BindBean UserProjectRolesTable userProjectRolesTable);
}