db.go
db.go - Overview
-
Overview The
db.go
file defines theRepo
struct and its associated methods for managing license keys and feature flags in a database. It handles operations such as retrieving, inserting, and updating license information, as well as managing feature status (active/inactive) and usage. -
Detailed Documentation
Repo
- Purpose: Represents the license repository, providing methods to interact with the database for license and feature management.
- Fields:
db
:*sqlx.DB
- Database connection for license data.store
:sqlstore.SQLStore
- SQL store instance.
NewLicenseRepo
- Purpose: Creates a new instance of the
Repo
struct. - Parameters:
db
:*sqlx.DB
- Database connection.store
:sqlstore.SQLStore
- The sql store.
- Returns:
Repo
- A newRepo
instance.
Repo.GetLicensesV3
- Purpose: Retrieves all license v3 data from the
licenses_v3
table. - Parameters:
ctx
:context.Context
- Context for the database operation.
- Returns:
([]*model.LicenseV3, error)
- A slice ofLicenseV3
pointers or an error if the operation fails.
Repo.GetActiveLicense
- Purpose: Fetches the latest active license from the database. Converts the v3 license into v2.
- Parameters:
ctx
:context.Context
- Context for the database operation.
- Returns:
(*model.License, *basemodel.ApiError)
- A pointer to the activeLicense
struct and a possibleApiError
. Returns nil license and nil error if no active license is found.
Repo.GetActiveLicenseV3
- Purpose: Retrieves the latest active license v3 from the database.
- Parameters:
ctx
:context.Context
- Context for the database operation.
- Returns:
(*model.LicenseV3, error)
- A pointer to the activeLicenseV3
struct or an error if the operation fails. Returns nil if no active license is found.
Repo.InsertLicenseV3
- Purpose: Inserts a new license v3 into the
licenses_v3
table. - Parameters:
ctx
:context.Context
- Context for the database operation.l
:*model.LicenseV3
- Pointer to theLicenseV3
struct containing license data.
- Returns:
*model.ApiError
- AnApiError
if the operation fails. Returns nil on success.
Repo.UpdateLicenseV3
- Purpose: Updates an existing license v3 in the
licenses_v3
table. - Parameters:
ctx
:context.Context
- Context for the database operation.l
:*model.LicenseV3
- Pointer to theLicenseV3
struct containing updated license data.
- Returns:
error
- An error if the operation fails, nil otherwise.
Repo.CreateFeature
- Purpose: Creates a new feature in the database.
- Parameters:
req
:*types.FeatureStatus
- Pointer to theFeatureStatus
struct containing feature data.
- Returns:
*basemodel.ApiError
- AnApiError
if the operation fails, nil otherwise.
Repo.GetFeature
- Purpose: Retrieves a feature from the database by its name.
- Parameters:
featureName
:string
- Name of the feature to retrieve.
- Returns:
(types.FeatureStatus, error)
- TheFeatureStatus
struct and an error if the operation fails. Returnsbasemodel.ErrFeatureUnavailable
if the feature is not found.
Repo.GetAllFeatures
- Purpose: Retrieves all features from the database.
- Parameters: None
- Returns:
([]basemodel.Feature, error)
- A slice ofFeature
structs and an error if the operation fails.
Repo.UpdateFeature
- Purpose: Updates an existing feature in the database.
- Parameters:
req
:types.FeatureStatus
- TheFeatureStatus
struct containing updated feature data.
- Returns:
error
- An error if the operation fails, nil otherwise.
Repo.InitFeatures
- Purpose: Initializes features in the database. Creates a feature if it doesn't exist, otherwise updates it.
- Parameters:
req
:[]types.FeatureStatus
- A slice ofFeatureStatus
structs containing feature data.
- Returns:
error
- An error if the operation fails, nil otherwise.
-
Code Examples N/A
-
Clarity and Accuracy The documentation is based on the code provided.
-
Markdown & MDX Perfection Verified.
-
Edge Cases To Avoid Breaking MDX Verified.
Include in Getting Started: NO