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

Add postgres samples #396

Merged
merged 1 commit into from
May 26, 2017
Merged

Add postgres samples #396

merged 1 commit into from
May 26, 2017

Conversation

ace-n
Copy link
Contributor

@ace-n ace-n commented May 20, 2017

Don't merge this (yet): some region tags have changed, and the docs have not been updated accordingly.

@ace-n ace-n added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label May 20, 2017
@ace-n ace-n requested review from beccasaurus and jmdobry May 20, 2017 07:17
@codecov-io
Copy link

codecov-io commented May 20, 2017

Codecov Report

Merging #396 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #396   +/-   ##
=======================================
  Coverage   83.88%   83.88%           
=======================================
  Files           4        4           
  Lines         422      422           
=======================================
  Hits          354      354           
  Misses         68       68

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 37a3cb2...5880a0c. Read the comment docs.

Copy link
Member

@jmdobry jmdobry left a comment

Choose a reason for hiding this comment

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

I feel like this PR is missing an update to the app.yaml file?

Also, why not collapse the MYSQL_ and POSTGRES_ environment variables in variables that are more generic, like DB_USER, DB_PASSWORD, etc. so you don't have to document two sets of variables? The one variable that would control which database to use would be that SQL_CLIENT variable.

],
"msg": "Last 10 visits:",
"args": ["server.js"]
},
"deploy": {
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The line below it seems to be MySQL-specific environment variables - but if we use the same environment variables for both clients, then I'll add it back in + update it accordingly.

const crypto = require('crypto');

const app = express();
app.enable('trust proxy');
// [END setup]
let knex;

function connectMysql () {
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this can be simplified, do we really need two different connection methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was wondering about this as well. The only difference between these two is the client (mysql vs pg), but I wanted two discrete, 'copy-and-paste' samples for both SQL options.

Copy link
Member

Choose a reason for hiding this comment

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

I still think you only need one connection method. Just set client in the Knex options to process.env.SQL_CLIENT, then the docs just need to tell the user to set the SQL_CLIENT env var.

@ace-n
Copy link
Contributor Author

ace-n commented May 24, 2017

FYI, the "samples test app" failure is likely due to some configuration (or configuration-processing) issue. @jmdobry see trace below, or let me know if you want me to dig further into it.

➜  samples test app              
app: Starting app in: /Users/anassri/Desktop/nodejs-docs-samples/appengine/cloudsql
app: Using port: 45032
app: Running: node app.js
app: Child process ID: 4443
module.js:471
    throw err;
    ^

Error: Cannot find module '/Users/anassri/Desktop/nodejs-docs-samples/appengine/cloudsql/app.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
/Users/anassri/.nvm/versions/node/v6.10.0/lib/node_modules/@google-cloud/nodejs-repo-tools/src/utils/index.js:121
    if (arg.red) {
           ^

TypeError: Cannot read property 'red' of null
    at console.error.args.map (/Users/anassri/.nvm/versions/node/v6.10.0/lib/node_modules/@google-cloud/nodejs-repo-tools/src/utils/index.js:121:12)
    at Array.map (native)
    at Object.exports.error (/Users/anassri/.nvm/versions/node/v6.10.0/lib/node_modules/@google-cloud/nodejs-repo-tools/src/utils/index.js:120:94)
    at ChildProcess.childProcess.spawn.on (/Users/anassri/.nvm/versions/node/v6.10.0/lib/node_modules/@google-cloud/nodejs-repo-tools/src/cli/commands/test_commands/app.js:142:17)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)

const crypto = require('crypto');

const app = express();
app.enable('trust proxy');
// [END setup]
let knex;

function connectMysql () {
Copy link
Member

Choose a reason for hiding this comment

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

I still think you only need one connection method. Just set client in the Knex options to process.env.SQL_CLIENT, then the docs just need to tell the user to set the SQL_CLIENT env var.

mysql> grant all on YOUR_DATABASE.* to 'YOUR_USER'@'%';
mysql> create database `YOUR_DATABASE`;
mysql> create user 'YOUR_USER'@'%' identified by 'PASSWORD';
mysql> grant all on YOUR_DATABASE.* to 'YOUR_USER'@'%';

1. Set the `MYSQL_USER`, `MYSQL_PASSWORD`, and `MYSQL_DATABASE` environment
Copy link
Member

Choose a reason for hiding this comment

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

These env vars need to be updated to the generic ones.

1. Update the values in in `app.yaml` with your instance configuration.
export POSTGRES_USER="..."
export POSTGRES_PASSWORD="..."
export POSTGRES_DATABASE="..."
Copy link
Member

Choose a reason for hiding this comment

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

These env vars need to be updated to the generic ones.


export MYSQL_USER="..."
export MYSQL_PASSWORD="..."
export MYSQL_DATABASE="..."
Copy link
Member

Choose a reason for hiding this comment

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

These env vars need to be updated to the generic ones.

Then, create a user (using the button in the *Access Control* > *Users* tab) and a
database (using the button in the *Databases* tab).

1. Set the `POSTGRES_USER`, `POSTGRES_PASSWORD`, and `POSTGRES_DATABASE` environment
Copy link
Member

Choose a reason for hiding this comment

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

These env vars need to be updated to the generic ones.

mysql> grant all on YOUR_DATABASE.* to 'YOUR_USER'@'%';
mysql> create database `YOUR_DATABASE`;
mysql> create user 'YOUR_USER'@'%' identified by 'PASSWORD';
mysql> grant all on YOUR_DATABASE.* to 'YOUR_USER'@'%';
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary still? The postgres docs below indicate this can all be done with the Cloud Console.

console.log(result);
// Connect to the database
return resolve(Knex({
client: 'mysql',
Copy link
Member

Choose a reason for hiding this comment

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

Again, I think we only need one connection method, just set the client Knex option to process.env.SQL_CLIENT.

// [END postgresMain]
};

exports.mysqlMain = function () {
Copy link
Member

Choose a reason for hiding this comment

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

Only need one main function


// Get type of SQL client to use
const sqlClient = process.env.SQL_CLIENT;
if (sqlClient === 'pg') {
Copy link
Member

Choose a reason for hiding this comment

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

no need for conditional if we just rely on passing process.env.SQL_CLIENT to the Knex constructor

// [END listen]
// Get type of SQL client to use
const sqlClient = process.env.SQL_CLIENT;
if (sqlClient === 'pg') {
Copy link
Member

Choose a reason for hiding this comment

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

No need for conditional if we rely on passing process.env.SQL_CLIENT to the Knex constructor

@jmdobry
Copy link
Member

jmdobry commented May 25, 2017

re: test error - What version of repo tools do you have?

"deploy": {
"substitutions": "YOUR_USER=$MYSQL_USER,YOUR_PASSWORD=$MYSQL_PASSWORD,YOUR_DATABASE=$MYSQL_DATABASE,YOUR_INSTANCE_CONNECTION_NAME=$INSTANCE_CONNECTION_NAME"
"substitutions": "YOUR_SQL_CLIENT=$SQL_CLIENT,YOUR_USER=$SQL_USER,YOUR_PASSWORD=$SQL_PASSWORD,YOUR_DATABASE=$SQL_DATABASE,YOUR_INSTANCE_CONNECTION_NAME=$INSTANCE_CONNECTION_NAME",
"startArgs": [
Copy link
Member

Choose a reason for hiding this comment

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

s/startArgs/args/

Copy link
Member

@jmdobry jmdobry left a comment

Choose a reason for hiding this comment

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

I think yarn needs to get run again to update the yarn.lock file. Do you have the latest version of yarn?

@@ -35,19 +35,18 @@
"test": {
Copy link
Member

Choose a reason for hiding this comment

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

Missing a dependency on pg. Run yarn add pg

Copy link
Member

Choose a reason for hiding this comment

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

Missing also a dependency on knex

@@ -35,19 +35,18 @@
"test": {
Copy link
Member

Choose a reason for hiding this comment

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

Missing also a dependency on knex

database: process.env.SQL_DATABASE
};

if (process.env.INSTANCE_CONNECTION_NAME) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should change to:

if (process.env.INSTANCE_CONNECTION_NAME && process.env.NODE_ENV === 'prod') {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be prod, or production?

Copy link
Member

Choose a reason for hiding this comment

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

You're right, should be production

Add README

Address comments; 'samples test app' still fails

Address comments + make tests pass

Enable Cloud SQL tests.
@ace-n ace-n merged commit 17f71e0 into master May 26, 2017
@ace-n ace-n deleted the add-postgres-2 branch June 30, 2017 19:23
ahrarmonsur pushed a commit that referenced this pull request Nov 8, 2022
BREAKING CHANGE: The library now supports Node.js v10+. The last version to support Node.js v8 is tagged legacy-8 on NPM.

New feature: methods with pagination now support async iteration.
ace-n pushed a commit that referenced this pull request Nov 10, 2022
BREAKING CHANGE: The library now supports Node.js v10+. The last version to support Node.js v8 is tagged legacy-8 on NPM.

New feature: methods with pagination now support async iteration.
ahrarmonsur pushed a commit that referenced this pull request Nov 16, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
ahrarmonsur pushed a commit that referenced this pull request Nov 16, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
ahrarmonsur pushed a commit that referenced this pull request Nov 16, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
ahrarmonsur pushed a commit that referenced this pull request Nov 16, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
ahrarmonsur pushed a commit that referenced this pull request Nov 16, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
ace-n pushed a commit that referenced this pull request Nov 17, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
NimJay pushed a commit that referenced this pull request Nov 19, 2022
Co-authored-by: Justin Beckwith <justin.beckwith@gmail.com>
NimJay pushed a commit that referenced this pull request Nov 19, 2022
Co-authored-by: Justin Beckwith <justin.beckwith@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge Indicates a pull request not ready for merge, due to either quality or timing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants