Add new comparators: Exists and NotExists ()

This commit is contained in:
sunboyy 2022-11-12 16:09:59 +07:00 committed by GitHub
parent 482dd095a6
commit 1e0ab5d701
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 232 additions and 23 deletions
examples/getting-started

View file

@ -12,7 +12,7 @@ import (
// Replace these values with your own connection option. This connection option is hard-coded for easy
// demonstration. Make sure not to hard-code the credentials in the production code.
const (
connectionString = "mongodb://lineman:lineman@localhost:27017"
connectionString = "mongodb://admin:password@localhost:27017"
databaseName = "repogen_examples"
collectionName = "gettingstarted_user"
)

View file

@ -16,27 +16,32 @@ type UserModel struct {
//go:generate repogen -src=user.go -dest=user_repo.go -model=UserModel -repo=UserRepository
// UserRepository is an interface that describes the specification of querying user data in the database
// UserRepository is an interface that describes the specification of querying
// user data in the database.
type UserRepository interface {
// InsertOne stores userModel into the database and returns inserted ID if insertion
// succeeds and returns error if insertion fails.
// InsertOne stores userModel into the database and returns inserted ID
// if insertion succeeds and returns error if insertion fails.
InsertOne(ctx context.Context, userModel *UserModel) (interface{}, error)
// FindByUsername queries user by username. If a user with specified username exists,
// the user will be returned. Otherwise, error will be returned.
// FindByUsername queries user by username. If a user with specified
// username exists, the user will be returned. Otherwise, error will be
// returned.
FindByUsername(ctx context.Context, username string) (*UserModel, error)
// UpdateDisplayNameByID updates a user with the specified ID with a new display name.
// If there is a user matches the query, it will return true. Error will be returned
// only when error occurs while accessing the database.
// UpdateDisplayNameByID updates a user with the specified ID with a new
// display name. If there is a user matches the query, it will return
// true. Error will be returned only when error occurs while accessing
// the database.
UpdateDisplayNameByID(ctx context.Context, displayName string, id primitive.ObjectID) (bool, error)
// DeleteByCity deletes users that have `city` value match the parameter and returns
// the match count. The error will be returned only when error occurs while accessing
// the database. This is a MANY mode because the first return type is an integer.
// DeleteByCity deletes users that have `city` value match the parameter
// and returns the match count. The error will be returned only when
// error occurs while accessing the database. This is a MANY mode
// because the first return type is an integer.
DeleteByCity(ctx context.Context, city string) (int, error)
// CountByCity returns the number of rows that match the given city parameter. If an
// error occurs while accessing the database, error value will be returned.
// CountByCity returns the number of rows that match the given city
// parameter. If an error occurs while accessing the database, error
// value will be returned.
CountByCity(ctx context.Context, city string) (int, error)
}