Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions handwritten/spanner-pg/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules
**/coverage
build/
docs/
test/pg-suite/
4 changes: 4 additions & 0 deletions handwritten/spanner-pg/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": true,
"extends": "./node_modules/gts"
}
12 changes: 12 additions & 0 deletions handwritten/spanner-pg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**/*.log
**/node_modules
/.coverage
/coverage
/.nyc_output
/docs/
/out/
/build/
*.lock
.DS_Store
package-lock.json
pg-suite
30 changes: 30 additions & 0 deletions handwritten/spanner-pg/.mocharc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

const config = {
"enable-source-maps": true,
"throw-deprecation": true,
"timeout": 10000,
"recursive": true
}
if (process.env.MOCHA_THROW_DEPRECATION === 'false') {
delete config['throw-deprecation'];
}
if (process.env.MOCHA_REPORTER) {
config.reporter = process.env.MOCHA_REPORTER;
}
if (process.env.MOCHA_REPORTER_OUTPUT) {
config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`;
}
module.exports = config
5 changes: 5 additions & 0 deletions handwritten/spanner-pg/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules
**/coverage
build/
docs/
test/pg-suite/
17 changes: 17 additions & 0 deletions handwritten/spanner-pg/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

module.exports = {
...require('gts/.prettierrc.json')
}
63 changes: 63 additions & 0 deletions handwritten/spanner-pg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@google-cloud/spanner-pg",
"version": "0.1.0",
"description": "Node.js pg-compatible driver wrapper for Google Cloud Spanner",
"repository": {
"type": "git",
"url": "https://github.com/googleapis/google-cloud-node.git",
"directory": "handwritten/spanner-pg"
},
"license": "Apache-2.0",
"author": "Google LLC",
"main": "./build/cjs/src/index.cjs",
"module": "./build/esm/src/index.js",
"types": "./build/cjs/src/index.d.ts",
"type": "module",
"exports": {
".": {
"import": {
"types": "./build/esm/src/index.d.ts",
"default": "./build/esm/src/index.js"
},
"require": {
"types": "./build/cjs/src/index.d.ts",
"default": "./build/cjs/src/index.cjs"
}
}
},
"files": [
"build/esm/src",
"build/cjs/src"
],
"scripts": {
"clean": "gts clean",
"compile:esm": "tsc -p .",
"compile:cjs": "tsc -p ./tsconfig.cjs.json && babel build/cjs --out-dir build/cjs --out-file-extension .cjs && node scripts/fix-extensions.cjs",
"compile": "npm run compile:esm && npm run compile:cjs",
"fix": "gts fix",
"lint": "gts check",
"prepare": "npm run compile",
"test:esm": "c8 mocha build/esm/test/**/*.js",
"test:cjs": "c8 mocha build/cjs/test/**/*.cjs",
"test": "npm run test:esm && npm run test:cjs"
},
"dependencies": {
"spannerlib-node": "file:/Users/gargsurbhi/Work/Github/go-sql-spanner/spannerlib/wrappers/spannerlib-node",
"@google-cloud/spanner": "^8.7.1"
},
Comment on lines +44 to +47

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The dependency spannerlib-node points to a hardcoded local file path on your machine (file:/Users/gargsurbhi/...). This will cause installation and build failures in CI/CD environments and for other developers. Please replace this with a published version or a workspace reference.

Suggested change
"dependencies": {
"spannerlib-node": "file:/Users/gargsurbhi/Work/Github/go-sql-spanner/spannerlib/wrappers/spannerlib-node",
"@google-cloud/spanner": "^8.7.1"
},
"dependencies": {
"spannerlib-node": "^0.1.0",
"@google-cloud/spanner": "^8.7.1"
},

"devDependencies": {
"@types/mocha": "^10.0.10",
"@types/node": "^22.13.9",
"@types/sinon": "^17.0.4",
"c8": "^10.1.3",
"gts": "^6.0.2",
"mocha": "^11.1.0",
"sinon": "^21.0.3",
"typescript": "^5.8.2",
"@babel/core": "^7.24.0",
"@babel/cli": "^7.23.9"
},
"engines": {
"node": ">=18"
}
}
42 changes: 42 additions & 0 deletions handwritten/spanner-pg/scripts/fix-extensions.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

const fs = require('fs');
const path = require('path');

const cjsDir = path.join(__dirname, '../build/cjs');

function traverseDir(dir) {
fs.readdirSync(dir).forEach(file => {
const fullPath = path.join(dir, file);
if (fs.statSync(fullPath).isDirectory()) {
traverseDir(fullPath);
} else if (fullPath.endsWith('.cjs')) {
let content = fs.readFileSync(fullPath, 'utf8');
// Replace require paths starting with . / or .. / and ending with .js
content = content.replace(/require\(['"]((\.|\.\.)\/[^'"]+)\.js['"]\)/g, "require('$1.cjs')");
// Fix import.meta.url syntax error in CommonJS
content = content.replace(/import\.meta\.url/g, '""');
fs.writeFileSync(fullPath, content);
} else if (fullPath.endsWith('.js')) {
// Delete the original .js file generated by tsc
fs.unlinkSync(fullPath);
}
});
}

if (fs.existsSync(cjsDir)) {
traverseDir(cjsDir);
console.log('Fixed extensions in .cjs files and removed .js files in build/cjs');
}
51 changes: 51 additions & 0 deletions handwritten/spanner-pg/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import {Client} from './lib/client.js';
import {Pool} from './lib/pool.js';
import {Query} from './lib/query.js';
import {types} from './lib/types.js';

export {Client, Pool, Query, types};
export const native = {Client, Pool};

export const defaults = {
host: 'localhost',
port: 5432,
user: 'postgres',
password: '',
database: 'postgres',
};

export class DatabaseError extends Error {
severity?: string;
code?: string;
detail?: string;
hint?: string;
position?: string;
internalPosition?: string;
internalQuery?: string;
where?: string;
schema?: string;
table?: string;
column?: string;
dataType?: string;
constraint?: string;
file?: string;
line?: string;
routine?: string;
}

export const escapeIdentifier = (str: string) => `"${str.replace(/"/g, '""')}"`;
export const escapeLiteral = (str: string) => `'${str.replace(/'/g, "''")}'`;
Loading
Loading