// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.29.0 // source: company.sql package dbgen import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const CreateCompany = `-- name: CreateCompany :one INSERT INTO companies ( name, slug, admin_id, wallet_id, deducted_percentage, is_active ) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id, name, slug, admin_id, wallet_id, deducted_percentage, is_active, created_at, updated_at ` type CreateCompanyParams struct { Name string `json:"name"` Slug string `json:"slug"` AdminID int64 `json:"admin_id"` WalletID int64 `json:"wallet_id"` DeductedPercentage float32 `json:"deducted_percentage"` IsActive bool `json:"is_active"` } func (q *Queries) CreateCompany(ctx context.Context, arg CreateCompanyParams) (Company, error) { row := q.db.QueryRow(ctx, CreateCompany, arg.Name, arg.Slug, arg.AdminID, arg.WalletID, arg.DeductedPercentage, arg.IsActive, ) var i Company err := row.Scan( &i.ID, &i.Name, &i.Slug, &i.AdminID, &i.WalletID, &i.DeductedPercentage, &i.IsActive, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const DeleteCompany = `-- name: DeleteCompany :exec DELETE FROM companies WHERE id = $1 ` func (q *Queries) DeleteCompany(ctx context.Context, id int64) error { _, err := q.db.Exec(ctx, DeleteCompany, id) return err } const GetAllCompanies = `-- name: GetAllCompanies :many SELECT id, name, slug, admin_id, wallet_id, deducted_percentage, is_active, created_at, updated_at, balance, wallet_is_active, admin_first_name, admin_last_name, admin_phone_number FROM companies_details WHERE ( name ILIKE '%' || $1 || '%' OR admin_first_name ILIKE '%' || $1 || '%' OR admin_last_name ILIKE '%' || $1 || '%' OR admin_phone_number ILIKE '%' || $1 || '%' OR $1 IS NULL ) AND ( created_at > $2 OR $2 IS NULL ) AND ( created_at < $3 OR $3 IS NULL ) ` type GetAllCompaniesParams struct { Query pgtype.Text `json:"query"` CreatedBefore pgtype.Timestamp `json:"created_before"` CreatedAfter pgtype.Timestamp `json:"created_after"` } func (q *Queries) GetAllCompanies(ctx context.Context, arg GetAllCompaniesParams) ([]CompaniesDetail, error) { rows, err := q.db.Query(ctx, GetAllCompanies, arg.Query, arg.CreatedBefore, arg.CreatedAfter) if err != nil { return nil, err } defer rows.Close() var items []CompaniesDetail for rows.Next() { var i CompaniesDetail if err := rows.Scan( &i.ID, &i.Name, &i.Slug, &i.AdminID, &i.WalletID, &i.DeductedPercentage, &i.IsActive, &i.CreatedAt, &i.UpdatedAt, &i.Balance, &i.WalletIsActive, &i.AdminFirstName, &i.AdminLastName, &i.AdminPhoneNumber, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const GetCompanyByID = `-- name: GetCompanyByID :one SELECT id, name, slug, admin_id, wallet_id, deducted_percentage, is_active, created_at, updated_at, balance, wallet_is_active, admin_first_name, admin_last_name, admin_phone_number FROM companies_details WHERE id = $1 ` func (q *Queries) GetCompanyByID(ctx context.Context, id int64) (CompaniesDetail, error) { row := q.db.QueryRow(ctx, GetCompanyByID, id) var i CompaniesDetail err := row.Scan( &i.ID, &i.Name, &i.Slug, &i.AdminID, &i.WalletID, &i.DeductedPercentage, &i.IsActive, &i.CreatedAt, &i.UpdatedAt, &i.Balance, &i.WalletIsActive, &i.AdminFirstName, &i.AdminLastName, &i.AdminPhoneNumber, ) return i, err } const GetCompanyUsingSlug = `-- name: GetCompanyUsingSlug :one SELECT id, name, slug, admin_id, wallet_id, deducted_percentage, is_active, created_at, updated_at FROM companies WHERE slug = $1 ` func (q *Queries) GetCompanyUsingSlug(ctx context.Context, slug string) (Company, error) { row := q.db.QueryRow(ctx, GetCompanyUsingSlug, slug) var i Company err := row.Scan( &i.ID, &i.Name, &i.Slug, &i.AdminID, &i.WalletID, &i.DeductedPercentage, &i.IsActive, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const SearchCompanyByName = `-- name: SearchCompanyByName :many SELECT id, name, slug, admin_id, wallet_id, deducted_percentage, is_active, created_at, updated_at, balance, wallet_is_active, admin_first_name, admin_last_name, admin_phone_number FROM companies_details WHERE name ILIKE '%' || $1 || '%' ` func (q *Queries) SearchCompanyByName(ctx context.Context, dollar_1 pgtype.Text) ([]CompaniesDetail, error) { rows, err := q.db.Query(ctx, SearchCompanyByName, dollar_1) if err != nil { return nil, err } defer rows.Close() var items []CompaniesDetail for rows.Next() { var i CompaniesDetail if err := rows.Scan( &i.ID, &i.Name, &i.Slug, &i.AdminID, &i.WalletID, &i.DeductedPercentage, &i.IsActive, &i.CreatedAt, &i.UpdatedAt, &i.Balance, &i.WalletIsActive, &i.AdminFirstName, &i.AdminLastName, &i.AdminPhoneNumber, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const UpdateCompany = `-- name: UpdateCompany :exec UPDATE companies SET name = COALESCE($2, name), admin_id = COALESCE($3, admin_id), is_active = COALESCE($4, is_active), deducted_percentage = COALESCE( $5, deducted_percentage ), slug = COALESCE($6, slug), updated_at = CURRENT_TIMESTAMP WHERE id = $1 ` type UpdateCompanyParams struct { ID int64 `json:"id"` Name pgtype.Text `json:"name"` AdminID pgtype.Int8 `json:"admin_id"` IsActive pgtype.Bool `json:"is_active"` DeductedPercentage pgtype.Float4 `json:"deducted_percentage"` Slug pgtype.Text `json:"slug"` } func (q *Queries) UpdateCompany(ctx context.Context, arg UpdateCompanyParams) error { _, err := q.db.Exec(ctx, UpdateCompany, arg.ID, arg.Name, arg.AdminID, arg.IsActive, arg.DeductedPercentage, arg.Slug, ) return err }