summaryrefslogtreecommitdiff
path: root/internal/queries/queries.sql.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/queries/queries.sql.go')
-rw-r--r--internal/queries/queries.sql.go542
1 files changed, 542 insertions, 0 deletions
diff --git a/internal/queries/queries.sql.go b/internal/queries/queries.sql.go
new file mode 100644
index 0000000..3da8b98
--- /dev/null
+++ b/internal/queries/queries.sql.go
@@ -0,0 +1,542 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+// sqlc v1.29.0
+// source: queries.sql
+
+package queries
+
+import (
+ "context"
+ "database/sql"
+ "time"
+)
+
+const createClient = `-- name: CreateClient :one
+insert into client (name, email, billable_rate)
+values (?1, ?2, ?3)
+returning id, name, email, billable_rate, created_at
+`
+
+type CreateClientParams struct {
+ Name string
+ Email sql.NullString
+ BillableRate sql.NullInt64
+}
+
+func (q *Queries) CreateClient(ctx context.Context, arg CreateClientParams) (Client, error) {
+ row := q.db.QueryRowContext(ctx, createClient, arg.Name, arg.Email, arg.BillableRate)
+ var i Client
+ err := row.Scan(
+ &i.ID,
+ &i.Name,
+ &i.Email,
+ &i.BillableRate,
+ &i.CreatedAt,
+ )
+ return i, err
+}
+
+const createProject = `-- name: CreateProject :one
+insert into project (name, client_id, billable_rate)
+values (?1, ?2, ?3)
+returning id, name, client_id, billable_rate, created_at
+`
+
+type CreateProjectParams struct {
+ Name string
+ ClientID int64
+ BillableRate sql.NullInt64
+}
+
+func (q *Queries) CreateProject(ctx context.Context, arg CreateProjectParams) (Project, error) {
+ row := q.db.QueryRowContext(ctx, createProject, arg.Name, arg.ClientID, arg.BillableRate)
+ var i Project
+ err := row.Scan(
+ &i.ID,
+ &i.Name,
+ &i.ClientID,
+ &i.BillableRate,
+ &i.CreatedAt,
+ )
+ return i, err
+}
+
+const createTimeEntry = `-- name: CreateTimeEntry :one
+insert into time_entry (start_time, description, client_id, project_id, billable_rate)
+values (
+ datetime('now', 'utc'),
+ ?1,
+ ?2,
+ ?3,
+ coalesce(
+ ?4,
+ (select p.billable_rate from project p where p.id = ?3),
+ (select c.billable_rate from client c where c.id = ?2)
+ )
+)
+returning id, start_time, end_time, description, client_id, project_id, billable_rate
+`
+
+type CreateTimeEntryParams struct {
+ Description sql.NullString
+ ClientID int64
+ ProjectID sql.NullInt64
+ BillableRate interface{}
+}
+
+func (q *Queries) CreateTimeEntry(ctx context.Context, arg CreateTimeEntryParams) (TimeEntry, error) {
+ row := q.db.QueryRowContext(ctx, createTimeEntry,
+ arg.Description,
+ arg.ClientID,
+ arg.ProjectID,
+ arg.BillableRate,
+ )
+ var i TimeEntry
+ err := row.Scan(
+ &i.ID,
+ &i.StartTime,
+ &i.EndTime,
+ &i.Description,
+ &i.ClientID,
+ &i.ProjectID,
+ &i.BillableRate,
+ )
+ return i, err
+}
+
+const createTimeEntryWithTimes = `-- name: CreateTimeEntryWithTimes :one
+insert into time_entry (start_time, end_time, description, client_id, project_id, billable_rate)
+values (
+ ?1,
+ ?2,
+ ?3,
+ ?4,
+ ?5,
+ coalesce(
+ ?6,
+ (select p.billable_rate from project p where p.id = ?5),
+ (select c.billable_rate from client c where c.id = ?4)
+ )
+)
+returning id, start_time, end_time, description, client_id, project_id, billable_rate
+`
+
+type CreateTimeEntryWithTimesParams struct {
+ StartTime time.Time
+ EndTime sql.NullTime
+ Description sql.NullString
+ ClientID int64
+ ProjectID sql.NullInt64
+ BillableRate interface{}
+}
+
+func (q *Queries) CreateTimeEntryWithTimes(ctx context.Context, arg CreateTimeEntryWithTimesParams) (TimeEntry, error) {
+ row := q.db.QueryRowContext(ctx, createTimeEntryWithTimes,
+ arg.StartTime,
+ arg.EndTime,
+ arg.Description,
+ arg.ClientID,
+ arg.ProjectID,
+ arg.BillableRate,
+ )
+ var i TimeEntry
+ err := row.Scan(
+ &i.ID,
+ &i.StartTime,
+ &i.EndTime,
+ &i.Description,
+ &i.ClientID,
+ &i.ProjectID,
+ &i.BillableRate,
+ )
+ return i, err
+}
+
+const findClient = `-- name: FindClient :many
+select c1.id, c1.name, c1.email, c1.billable_rate, c1.created_at from client c1 where c1.id = cast(?1 as integer)
+union all
+select c2.id, c2.name, c2.email, c2.billable_rate, c2.created_at from client c2 where c2.name = ?2
+`
+
+type FindClientParams struct {
+ ID int64
+ Name string
+}
+
+func (q *Queries) FindClient(ctx context.Context, arg FindClientParams) ([]Client, error) {
+ rows, err := q.db.QueryContext(ctx, findClient, arg.ID, arg.Name)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []Client
+ for rows.Next() {
+ var i Client
+ if err := rows.Scan(
+ &i.ID,
+ &i.Name,
+ &i.Email,
+ &i.BillableRate,
+ &i.CreatedAt,
+ ); err != nil {
+ return nil, err
+ }
+ items = append(items, i)
+ }
+ if err := rows.Close(); err != nil {
+ return nil, err
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
+
+const findProject = `-- name: FindProject :many
+select p1.id, p1.name, p1.client_id, p1.billable_rate, p1.created_at from project p1 where p1.id = cast(?1 as integer)
+union all
+select p2.id, p2.name, p2.client_id, p2.billable_rate, p2.created_at from project p2 where p2.name = ?2
+`
+
+type FindProjectParams struct {
+ ID int64
+ Name string
+}
+
+func (q *Queries) FindProject(ctx context.Context, arg FindProjectParams) ([]Project, error) {
+ rows, err := q.db.QueryContext(ctx, findProject, arg.ID, arg.Name)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []Project
+ for rows.Next() {
+ var i Project
+ if err := rows.Scan(
+ &i.ID,
+ &i.Name,
+ &i.ClientID,
+ &i.BillableRate,
+ &i.CreatedAt,
+ ); err != nil {
+ return nil, err
+ }
+ items = append(items, i)
+ }
+ if err := rows.Close(); err != nil {
+ return nil, err
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
+
+const getActiveTimeEntry = `-- name: GetActiveTimeEntry :one
+select id, start_time, end_time, description, client_id, project_id, billable_rate from time_entry
+where end_time is null
+order by start_time desc
+limit 1
+`
+
+func (q *Queries) GetActiveTimeEntry(ctx context.Context) (TimeEntry, error) {
+ row := q.db.QueryRowContext(ctx, getActiveTimeEntry)
+ var i TimeEntry
+ err := row.Scan(
+ &i.ID,
+ &i.StartTime,
+ &i.EndTime,
+ &i.Description,
+ &i.ClientID,
+ &i.ProjectID,
+ &i.BillableRate,
+ )
+ return i, err
+}
+
+const getClientByName = `-- name: GetClientByName :one
+select id, name, email, billable_rate, created_at from client where name = ?1 limit 1
+`
+
+func (q *Queries) GetClientByName(ctx context.Context, name string) (Client, error) {
+ row := q.db.QueryRowContext(ctx, getClientByName, name)
+ var i Client
+ err := row.Scan(
+ &i.ID,
+ &i.Name,
+ &i.Email,
+ &i.BillableRate,
+ &i.CreatedAt,
+ )
+ return i, err
+}
+
+const getMonthSummaryByProject = `-- name: GetMonthSummaryByProject :many
+select
+ p.id as project_id,
+ p.name as project_name,
+ c.id as client_id,
+ c.name as client_name,
+ cast(sum(
+ case
+ when te.end_time is null then
+ (julianday('now', 'utc') - julianday(te.start_time)) * 24 * 60 * 60
+ else
+ (julianday(te.end_time) - julianday(te.start_time)) * 24 * 60 * 60
+ end
+ ) as integer) as total_seconds
+from time_entry te
+join client c on te.client_id = c.id
+left join project p on te.project_id = p.id
+where date(te.start_time) >= date('now', 'start of month')
+ and date(te.start_time) <= date('now')
+group by p.id, p.name, c.id, c.name
+order by c.name, p.name
+`
+
+type GetMonthSummaryByProjectRow struct {
+ ProjectID sql.NullInt64
+ ProjectName sql.NullString
+ ClientID int64
+ ClientName string
+ TotalSeconds int64
+}
+
+func (q *Queries) GetMonthSummaryByProject(ctx context.Context) ([]GetMonthSummaryByProjectRow, error) {
+ rows, err := q.db.QueryContext(ctx, getMonthSummaryByProject)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []GetMonthSummaryByProjectRow
+ for rows.Next() {
+ var i GetMonthSummaryByProjectRow
+ if err := rows.Scan(
+ &i.ProjectID,
+ &i.ProjectName,
+ &i.ClientID,
+ &i.ClientName,
+ &i.TotalSeconds,
+ ); err != nil {
+ return nil, err
+ }
+ items = append(items, i)
+ }
+ if err := rows.Close(); err != nil {
+ return nil, err
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
+
+const getMostRecentTimeEntry = `-- name: GetMostRecentTimeEntry :one
+select id, start_time, end_time, description, client_id, project_id, billable_rate from time_entry
+order by start_time desc
+limit 1
+`
+
+func (q *Queries) GetMostRecentTimeEntry(ctx context.Context) (TimeEntry, error) {
+ row := q.db.QueryRowContext(ctx, getMostRecentTimeEntry)
+ var i TimeEntry
+ err := row.Scan(
+ &i.ID,
+ &i.StartTime,
+ &i.EndTime,
+ &i.Description,
+ &i.ClientID,
+ &i.ProjectID,
+ &i.BillableRate,
+ )
+ return i, err
+}
+
+const getProjectByNameAndClient = `-- name: GetProjectByNameAndClient :one
+select id, name, client_id, billable_rate, created_at from project where name = ?1 and client_id = ?2 limit 1
+`
+
+type GetProjectByNameAndClientParams struct {
+ Name string
+ ClientID int64
+}
+
+func (q *Queries) GetProjectByNameAndClient(ctx context.Context, arg GetProjectByNameAndClientParams) (Project, error) {
+ row := q.db.QueryRowContext(ctx, getProjectByNameAndClient, arg.Name, arg.ClientID)
+ var i Project
+ err := row.Scan(
+ &i.ID,
+ &i.Name,
+ &i.ClientID,
+ &i.BillableRate,
+ &i.CreatedAt,
+ )
+ return i, err
+}
+
+const getWeekSummaryByProject = `-- name: GetWeekSummaryByProject :many
+select
+ p.id as project_id,
+ p.name as project_name,
+ c.id as client_id,
+ c.name as client_name,
+ cast(sum(
+ case
+ when te.end_time is null then
+ (julianday('now', 'utc') - julianday(te.start_time)) * 24 * 60 * 60
+ else
+ (julianday(te.end_time) - julianday(te.start_time)) * 24 * 60 * 60
+ end
+ ) as integer) as total_seconds
+from time_entry te
+join client c on te.client_id = c.id
+left join project p on te.project_id = p.id
+where date(te.start_time) >= date('now', 'weekday 1', '-6 days')
+ and date(te.start_time) <= date('now')
+group by p.id, p.name, c.id, c.name
+order by c.name, p.name
+`
+
+type GetWeekSummaryByProjectRow struct {
+ ProjectID sql.NullInt64
+ ProjectName sql.NullString
+ ClientID int64
+ ClientName string
+ TotalSeconds int64
+}
+
+func (q *Queries) GetWeekSummaryByProject(ctx context.Context) ([]GetWeekSummaryByProjectRow, error) {
+ rows, err := q.db.QueryContext(ctx, getWeekSummaryByProject)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []GetWeekSummaryByProjectRow
+ for rows.Next() {
+ var i GetWeekSummaryByProjectRow
+ if err := rows.Scan(
+ &i.ProjectID,
+ &i.ProjectName,
+ &i.ClientID,
+ &i.ClientName,
+ &i.TotalSeconds,
+ ); err != nil {
+ return nil, err
+ }
+ items = append(items, i)
+ }
+ if err := rows.Close(); err != nil {
+ return nil, err
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
+
+const listAllClients = `-- name: ListAllClients :many
+select id, name, email, billable_rate, created_at from client
+order by name
+`
+
+func (q *Queries) ListAllClients(ctx context.Context) ([]Client, error) {
+ rows, err := q.db.QueryContext(ctx, listAllClients)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []Client
+ for rows.Next() {
+ var i Client
+ if err := rows.Scan(
+ &i.ID,
+ &i.Name,
+ &i.Email,
+ &i.BillableRate,
+ &i.CreatedAt,
+ ); err != nil {
+ return nil, err
+ }
+ items = append(items, i)
+ }
+ if err := rows.Close(); err != nil {
+ return nil, err
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
+
+const listAllProjects = `-- name: ListAllProjects :many
+select p.id, p.name, p.client_id, p.billable_rate, p.created_at, c.name as client_name from project p
+join client c on p.client_id = c.id
+order by c.name, p.name
+`
+
+type ListAllProjectsRow struct {
+ ID int64
+ Name string
+ ClientID int64
+ BillableRate sql.NullInt64
+ CreatedAt sql.NullTime
+ ClientName string
+}
+
+func (q *Queries) ListAllProjects(ctx context.Context) ([]ListAllProjectsRow, error) {
+ rows, err := q.db.QueryContext(ctx, listAllProjects)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []ListAllProjectsRow
+ for rows.Next() {
+ var i ListAllProjectsRow
+ if err := rows.Scan(
+ &i.ID,
+ &i.Name,
+ &i.ClientID,
+ &i.BillableRate,
+ &i.CreatedAt,
+ &i.ClientName,
+ ); err != nil {
+ return nil, err
+ }
+ items = append(items, i)
+ }
+ if err := rows.Close(); err != nil {
+ return nil, err
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
+
+const stopTimeEntry = `-- name: StopTimeEntry :one
+update time_entry
+set end_time = datetime('now', 'utc')
+where id = (
+ select id
+ from time_entry
+ where end_time is null
+ order by start_time desc
+ limit 1
+)
+returning id, start_time, end_time, description, client_id, project_id, billable_rate
+`
+
+func (q *Queries) StopTimeEntry(ctx context.Context) (TimeEntry, error) {
+ row := q.db.QueryRowContext(ctx, stopTimeEntry)
+ var i TimeEntry
+ err := row.Scan(
+ &i.ID,
+ &i.StartTime,
+ &i.EndTime,
+ &i.Description,
+ &i.ClientID,
+ &i.ProjectID,
+ &i.BillableRate,
+ )
+ return i, err
+}