Capstone/ui/db/db.go

27 lines
450 B
Go
Raw Normal View History

2023-10-28 14:42:29 -04:00
package db
import (
"context"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
type Model interface {
Save(client *mongo.Client) error
Delete(client *mongo.Client) error
}
type DB struct {
client *mongo.Client
}
func NewClient(uri string) (*DB, error) {
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
if err != nil {
return nil, err
}
return &DB{client: client}, nil
}