Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 [Proposal]: Add template for a database connection based on user input #3

Open
3 tasks done
tuhinexe opened this issue Sep 20, 2024 · 2 comments
Open
3 tasks done

Comments

@tuhinexe
Copy link
Owner

tuhinexe commented Sep 20, 2024

Feature Proposal Description

It would be very helpful if there was an option to choose from an SQL DB and a NoSQL DB. ( PostgreSQL, MongoDB )

  • There should be templates for the mentioned DB connection configs.
  • Based on user selection the internal/config will contain a ConnectDB function to connect with Database,
  • localhost of the respective DB will be used for connection

Feature Examples

package main

import (
	"context"
	"log"

	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
)

var collection *mongo.Collection
var ctx = context.TODO()

func init() {
	clientOptions := options.Client().ApplyURI("mongodb://localhost:27017/")
	client, err := mongo.Connect(ctx, clientOptions)
	if err != nil {
		log.Fatal(err)
	}

	err = client.Ping(ctx, nil)
	if err != nil {
		log.Fatal(err)
	}

        return client
}

Checklist:

  • I agree to follow Optical's Code of Conduct.
  • I have searched for existing issues that describe my proposal before opening this one.
  • I understand that a proposal that does not meet these guidelines may be closed without explanation.
@tuhinexe
Copy link
Owner Author

tuhinexe commented Oct 9, 2024

This issue is fixed in PR #6

@tuhinexe tuhinexe closed this as completed Oct 9, 2024
@tuhinexe tuhinexe reopened this Oct 10, 2024
@tuhinexe
Copy link
Owner Author

Currently, both db configs are provided. It should be based on user input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant