// 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 createContractor = `-- name: CreateContractor :one insert into contractor (name, label, email) values (?1, ?2, ?3) returning id, name, label, email, created_at ` type CreateContractorParams struct { Name string Label string Email string } func (q *Queries) CreateContractor(ctx context.Context, arg CreateContractorParams) (Contractor, error) { row := q.db.QueryRowContext(ctx, createContractor, arg.Name, arg.Label, arg.Email) var i Contractor err := row.Scan( &i.ID, &i.Name, &i.Label, &i.Email, &i.CreatedAt, ) return i, err } const createInvoice = `-- name: CreateInvoice :one insert into invoice (year, month, number, client_id, total_amount) values (?1, ?2, ?3, ?4, ?5) returning id, year, month, number, client_id, total_amount, created_at ` type CreateInvoiceParams struct { Year int64 Month int64 Number int64 ClientID int64 TotalAmount int64 } func (q *Queries) CreateInvoice(ctx context.Context, arg CreateInvoiceParams) (Invoice, error) { row := q.db.QueryRowContext(ctx, createInvoice, arg.Year, arg.Month, arg.Number, arg.ClientID, arg.TotalAmount, ) var i Invoice err := row.Scan( &i.ID, &i.Year, &i.Month, &i.Number, &i.ClientID, &i.TotalAmount, &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, ?4 ) 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 sql.NullInt64 } 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 ( datetime(?1), datetime(?2), ?3, ?4, ?5, ?6 ) returning id, start_time, end_time, description, client_id, project_id, billable_rate ` type CreateTimeEntryWithTimesParams struct { StartTime interface{} EndTime interface{} Description sql.NullString ClientID int64 ProjectID sql.NullInt64 BillableRate sql.NullInt64 } 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 editTimeEntry = `-- name: EditTimeEntry :exec update time_entry set start_time = datetime(?1), end_time = datetime(?2), description = ?3, client_id = ?4, project_id = ?5, billable_rate = ?6 where id = ?7 ` type EditTimeEntryParams struct { StartTime interface{} EndTime interface{} Description sql.NullString ClientID int64 ProjectID sql.NullInt64 HourlyRate sql.NullInt64 EntryID int64 } func (q *Queries) EditTimeEntry(ctx context.Context, arg EditTimeEntryParams) error { _, err := q.db.ExecContext(ctx, editTimeEntry, arg.StartTime, arg.EndTime, arg.Description, arg.ClientID, arg.ProjectID, arg.HourlyRate, arg.EntryID, ) return 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 getContractor = `-- name: GetContractor :one select id, name, label, email, created_at from contractor order by id limit 1 ` func (q *Queries) GetContractor(ctx context.Context) (Contractor, error) { row := q.db.QueryRowContext(ctx, getContractor) var i Contractor err := row.Scan( &i.ID, &i.Name, &i.Label, &i.Email, &i.CreatedAt, ) return i, err } const getFilteredTimeEntries = `-- name: GetFilteredTimeEntries :many select id, start_time, end_time, description, client_id, project_id, billable_rate from time_entry where start_time >= ?1 and (?2 is null or start_time <= ?2) and (?3 is null or client_id = ?3) and (?4 is null or project_id = ?4) order by start_time desc ` type GetFilteredTimeEntriesParams struct { StartTime time.Time EndTime interface{} ClientID interface{} ProjectID interface{} } func (q *Queries) GetFilteredTimeEntries(ctx context.Context, arg GetFilteredTimeEntriesParams) ([]TimeEntry, error) { rows, err := q.db.QueryContext(ctx, getFilteredTimeEntries, arg.StartTime, arg.EndTime, arg.ClientID, arg.ProjectID, ) if err != nil { return nil, err } defer rows.Close() var items []TimeEntry for rows.Next() { var i TimeEntry if err := rows.Scan( &i.ID, &i.StartTime, &i.EndTime, &i.Description, &i.ClientID, &i.ProjectID, &i.BillableRate, ); 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 getHighestInvoiceNumber = `-- name: GetHighestInvoiceNumber :one select cast(coalesce(max(number), 0) as integer) as max_number from invoice where year = ?1 and month = ?2 ` type GetHighestInvoiceNumberParams struct { Year int64 Month int64 } func (q *Queries) GetHighestInvoiceNumber(ctx context.Context, arg GetHighestInvoiceNumberParams) (int64, error) { row := q.db.QueryRowContext(ctx, getHighestInvoiceNumber, arg.Year, arg.Month) var max_number int64 err := row.Scan(&max_number) return max_number, err } const getInvoiceDataByClient = `-- name: GetInvoiceDataByClient :many select te.id as time_entry_id, te.start_time, te.end_time, te.description, te.billable_rate as entry_billable_rate, c.id as client_id, c.name as client_name, c.billable_rate as client_billable_rate, p.id as project_id, p.name as project_name, p.billable_rate as project_billable_rate, cast(round((julianday(te.end_time) - julianday(te.start_time)) * 24 * 60 * 60) as integer) as duration_seconds, case when te.billable_rate is not null then 'entry' when p.billable_rate is not null then 'project' else 'client' end as rate_source from time_entry te join client c on te.client_id = c.id left join project p on te.project_id = p.id where c.id = ?1 and te.start_time >= ?2 and te.start_time <= ?3 and te.end_time is not null order by te.start_time ` type GetInvoiceDataByClientParams struct { ClientID int64 StartTime time.Time EndTime time.Time } type GetInvoiceDataByClientRow struct { TimeEntryID int64 StartTime time.Time EndTime sql.NullTime Description sql.NullString EntryBillableRate sql.NullInt64 ClientID int64 ClientName string ClientBillableRate sql.NullInt64 ProjectID sql.NullInt64 ProjectName sql.NullString ProjectBillableRate sql.NullInt64 DurationSeconds int64 RateSource string } func (q *Queries) GetInvoiceDataByClient(ctx context.Context, arg GetInvoiceDataByClientParams) ([]GetInvoiceDataByClientRow, error) { rows, err := q.db.QueryContext(ctx, getInvoiceDataByClient, arg.ClientID, arg.StartTime, arg.EndTime) if err != nil { return nil, err } defer rows.Close() var items []GetInvoiceDataByClientRow for rows.Next() { var i GetInvoiceDataByClientRow if err := rows.Scan( &i.TimeEntryID, &i.StartTime, &i.EndTime, &i.Description, &i.EntryBillableRate, &i.ClientID, &i.ClientName, &i.ClientBillableRate, &i.ProjectID, &i.ProjectName, &i.ProjectBillableRate, &i.DurationSeconds, &i.RateSource, ); 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 getInvoiceDataByProject = `-- name: GetInvoiceDataByProject :many select te.id as time_entry_id, te.start_time, te.end_time, te.description, te.billable_rate as entry_billable_rate, c.id as client_id, c.name as client_name, c.billable_rate as client_billable_rate, p.id as project_id, p.name as project_name, p.billable_rate as project_billable_rate, cast( 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 duration_seconds, case when te.billable_rate is not null then 'entry' when p.billable_rate is not null then 'project' else 'client' end as rate_source from time_entry te join client c on te.client_id = c.id join project p on te.project_id = p.id where p.id = ?1 and te.start_time >= ?2 and te.start_time <= ?3 and te.end_time is not null order by te.start_time ` type GetInvoiceDataByProjectParams struct { ProjectID int64 StartTime time.Time EndTime time.Time } type GetInvoiceDataByProjectRow struct { TimeEntryID int64 StartTime time.Time EndTime sql.NullTime Description sql.NullString EntryBillableRate sql.NullInt64 ClientID int64 ClientName string ClientBillableRate sql.NullInt64 ProjectID int64 ProjectName string ProjectBillableRate sql.NullInt64 DurationSeconds int64 RateSource string } func (q *Queries) GetInvoiceDataByProject(ctx context.Context, arg GetInvoiceDataByProjectParams) ([]GetInvoiceDataByProjectRow, error) { rows, err := q.db.QueryContext(ctx, getInvoiceDataByProject, arg.ProjectID, arg.StartTime, arg.EndTime) if err != nil { return nil, err } defer rows.Close() var items []GetInvoiceDataByProjectRow for rows.Next() { var i GetInvoiceDataByProjectRow if err := rows.Scan( &i.TimeEntryID, &i.StartTime, &i.EndTime, &i.Description, &i.EntryBillableRate, &i.ClientID, &i.ClientName, &i.ClientBillableRate, &i.ProjectID, &i.ProjectName, &i.ProjectBillableRate, &i.DurationSeconds, &i.RateSource, ); 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 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, 'localtime') >= date('now', 'localtime', 'start of month') and date(te.start_time) <= date('now', 'utc') 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 getTimeEntryById = `-- name: GetTimeEntryById :one select id, start_time, end_time, description, client_id, project_id, billable_rate from time_entry where id = ?1 ` func (q *Queries) GetTimeEntryById(ctx context.Context, entryID int64) (TimeEntry, error) { row := q.db.QueryRowContext(ctx, getTimeEntryById, entryID) var i TimeEntry err := row.Scan( &i.ID, &i.StartTime, &i.EndTime, &i.Description, &i.ClientID, &i.ProjectID, &i.BillableRate, ) return i, err } const getTimesheetDataByClient = `-- name: GetTimesheetDataByClient :many select te.id as time_entry_id, te.start_time, te.end_time, te.description, te.billable_rate as entry_billable_rate, c.id as client_id, c.name as client_name, c.billable_rate as client_billable_rate, p.id as project_id, p.name as project_name, p.billable_rate as project_billable_rate, cast(round((julianday(te.end_time) - julianday(te.start_time)) * 24 * 60 * 60) as integer) as duration_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 c.id = ?1 and te.start_time >= ?2 and te.start_time <= ?3 and te.end_time is not null order by te.start_time ` type GetTimesheetDataByClientParams struct { ClientID int64 StartTime time.Time EndTime time.Time } type GetTimesheetDataByClientRow struct { TimeEntryID int64 StartTime time.Time EndTime sql.NullTime Description sql.NullString EntryBillableRate sql.NullInt64 ClientID int64 ClientName string ClientBillableRate sql.NullInt64 ProjectID sql.NullInt64 ProjectName sql.NullString ProjectBillableRate sql.NullInt64 DurationSeconds int64 } func (q *Queries) GetTimesheetDataByClient(ctx context.Context, arg GetTimesheetDataByClientParams) ([]GetTimesheetDataByClientRow, error) { rows, err := q.db.QueryContext(ctx, getTimesheetDataByClient, arg.ClientID, arg.StartTime, arg.EndTime) if err != nil { return nil, err } defer rows.Close() var items []GetTimesheetDataByClientRow for rows.Next() { var i GetTimesheetDataByClientRow if err := rows.Scan( &i.TimeEntryID, &i.StartTime, &i.EndTime, &i.Description, &i.EntryBillableRate, &i.ClientID, &i.ClientName, &i.ClientBillableRate, &i.ProjectID, &i.ProjectName, &i.ProjectBillableRate, &i.DurationSeconds, ); 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 getTimesheetDataByProject = `-- name: GetTimesheetDataByProject :many select te.id as time_entry_id, te.start_time, te.end_time, te.description, te.billable_rate as entry_billable_rate, c.id as client_id, c.name as client_name, c.billable_rate as client_billable_rate, p.id as project_id, p.name as project_name, p.billable_rate as project_billable_rate, cast( 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 duration_seconds from time_entry te join client c on te.client_id = c.id join project p on te.project_id = p.id where p.id = ?1 and te.start_time >= ?2 and te.start_time <= ?3 and te.end_time is not null order by te.start_time ` type GetTimesheetDataByProjectParams struct { ProjectID int64 StartTime time.Time EndTime time.Time } type GetTimesheetDataByProjectRow struct { TimeEntryID int64 StartTime time.Time EndTime sql.NullTime Description sql.NullString EntryBillableRate sql.NullInt64 ClientID int64 ClientName string ClientBillableRate sql.NullInt64 ProjectID int64 ProjectName string ProjectBillableRate sql.NullInt64 DurationSeconds int64 } func (q *Queries) GetTimesheetDataByProject(ctx context.Context, arg GetTimesheetDataByProjectParams) ([]GetTimesheetDataByProjectRow, error) { rows, err := q.db.QueryContext(ctx, getTimesheetDataByProject, arg.ProjectID, arg.StartTime, arg.EndTime) if err != nil { return nil, err } defer rows.Close() var items []GetTimesheetDataByProjectRow for rows.Next() { var i GetTimesheetDataByProjectRow if err := rows.Scan( &i.TimeEntryID, &i.StartTime, &i.EndTime, &i.Description, &i.EntryBillableRate, &i.ClientID, &i.ClientName, &i.ClientBillableRate, &i.ProjectID, &i.ProjectName, &i.ProjectBillableRate, &i.DurationSeconds, ); 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 getTodaySummary = `-- name: GetTodaySummary :one select 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 where date(te.start_time, 'localtime') = date('now', 'localtime') ` func (q *Queries) GetTodaySummary(ctx context.Context) (int64, error) { row := q.db.QueryRowContext(ctx, getTodaySummary) var total_seconds int64 err := row.Scan(&total_seconds) return total_seconds, 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, 'localtime') >= date('now', 'localtime', 'weekday 0', '-6 days') and date(te.start_time) <= date('now', 'utc') 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 removeTimeEntry = `-- name: RemoveTimeEntry :exec delete from time_entry where id = ?1 ` func (q *Queries) RemoveTimeEntry(ctx context.Context, entryID int64) error { _, err := q.db.ExecContext(ctx, removeTimeEntry, entryID) return err } 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 } const updateActiveTimerDescription = `-- name: UpdateActiveTimerDescription :exec update time_entry set description = ?1 where id = ( select id from time_entry where end_time is null order by start_time desc limit 1 ) ` func (q *Queries) UpdateActiveTimerDescription(ctx context.Context, description sql.NullString) error { _, err := q.db.ExecContext(ctx, updateActiveTimerDescription, description) return err } const updateClient = `-- name: UpdateClient :one update client set name = ?1, email = ?2, billable_rate = ?3 where id = ?4 returning id, name, email, billable_rate, created_at ` type UpdateClientParams struct { Name string Email sql.NullString BillableRate sql.NullInt64 ID int64 } func (q *Queries) UpdateClient(ctx context.Context, arg UpdateClientParams) (Client, error) { row := q.db.QueryRowContext(ctx, updateClient, arg.Name, arg.Email, arg.BillableRate, arg.ID, ) var i Client err := row.Scan( &i.ID, &i.Name, &i.Email, &i.BillableRate, &i.CreatedAt, ) return i, err } const updateContractor = `-- name: UpdateContractor :one update contractor set name = ?1, label = ?2, email = ?3 where id = (select id from contractor limit 1) returning id, name, label, email, created_at ` type UpdateContractorParams struct { Name string Label string Email string } func (q *Queries) UpdateContractor(ctx context.Context, arg UpdateContractorParams) (Contractor, error) { row := q.db.QueryRowContext(ctx, updateContractor, arg.Name, arg.Label, arg.Email) var i Contractor err := row.Scan( &i.ID, &i.Name, &i.Label, &i.Email, &i.CreatedAt, ) return i, err } const updateProject = `-- name: UpdateProject :one update project set name = ?1, billable_rate = ?2 where id = ?3 returning id, name, client_id, billable_rate, created_at ` type UpdateProjectParams struct { Name string BillableRate sql.NullInt64 ID int64 } func (q *Queries) UpdateProject(ctx context.Context, arg UpdateProjectParams) (Project, error) { row := q.db.QueryRowContext(ctx, updateProject, arg.Name, arg.BillableRate, arg.ID) var i Project err := row.Scan( &i.ID, &i.Name, &i.ClientID, &i.BillableRate, &i.CreatedAt, ) return i, err }