Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add docs for connecting to MySQL with Django.#806

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
danielroseman wants to merge1 commit intoGoogleCloudPlatform:main
base:main
Choose a base branch
Loading
fromdanielroseman:django-docs

Conversation

@danielroseman
Copy link
Contributor

Refs#437

Note, I realised while writing this that it won't work with Postgres as there's no equivalent of theinstall_as_mysqldb call; I included a note explaining this.

pataquets reacted with thumbs up emoji
@danielrosemandanielroseman requested a review froma team as acode ownerJuly 29, 2023 13:14
@google-cla
Copy link

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View thisfailed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@jackwotherspoon
Copy link
Collaborator

Will test out this sample sometime this week and merge it if all goes smoothly 😄


classDatabaseWrapper(base.DatabaseWrapper):
defget_new_connection(self,conn_params):
return Connector().connect(**conn_params)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is this called on every new database connection? If so I'm not sure this is ideal as the first call toconnect() after a newConnector() is initialized it will cache the Cloud SQL instance data such as instance IP and certs used for SSL connection. Initializing a newConnector() on every database connection may cause SQL Admin API quotas to be exhausted and will not take advantage of the caching I mentioned. I will have to think about this a bit

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

After looking at this a bit closer I think we would want theConnector() to be initialized outside theDatabaseWrapper class so that it is only called once and can properly cache instances and re-use them.

Something that looks like this...

fromdjango.db.backends.mysqlimportbasefromgoogle.cloud.sql.connectorimportConnectorconnector=Connector()classDatabaseWrapper(base.DatabaseWrapper):defget_new_connection(self,conn_params):returnconnector.connect(**conn_params)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@jackwotherspoonjackwotherspoonjackwotherspoon left review comments

At least 1 approving review is required to merge this pull request.

Assignees

@jackwotherspoonjackwotherspoon

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@danielroseman@jackwotherspoon

[8]ページ先頭

©2009-2025 Movatter.jp