Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
gorm/
.idea
.DS_Store
node_modules
build/
31 changes: 25 additions & 6 deletions spannerlib/grpc-server/build-protos.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
#!/bin/bash

PATH="${PATH}:${HOME}/go/bin"
git submodule add git@github.com:googleapis/googleapis.git
ln -sf "${PWD}"/google/spannerlib googleapis/google/spannerlib

# 1. Clean up and fetch dependencies
# We DO NOT delete googleapis at the end because Node.js needs it at runtime
if [ ! -d "googleapis" ]; then
echo "Fetching dependency protos..."
git clone --depth 1 https://github.com/googleapis/googleapis.git
fi

# Link local proto into the structure
mkdir -p googleapis/google/spannerlib/v1
ln -sf "${PWD}/google/spannerlib/v1/spannerlib.proto" "googleapis/google/spannerlib/v1/spannerlib.proto"

cd googleapis || exit 1

# 2. Go generation
echo "Generating Go..."
protoc \
--go_out=../ \
--go_opt=paths=source_relative \
--go-grpc_out=../ \
--go-grpc_opt=paths=source_relative \
google/spannerlib/v1/spannerlib.proto

# 3. Java generation
echo "Generating Java..."
protoc \
--java_out=../../wrappers/spannerlib-java/src/main/java/ \
--plugin=protoc-gen-java-grpc=/Users/loite/protoc-gen-grpc-java-1.75.0-osx-aarch_64.exe \
--java-grpc_out=../../wrappers/spannerlib-java/src/main/java/ \
--java-grpc_opt=paths=source_relative \
google/spannerlib/v1/spannerlib.proto

# dotnet add package Grpc.Tools --version 2.76.0
# 4. C# generation
echo "Generating C#..."
protoc \
--csharp_out=../../wrappers/spannerlib-dotnet/spannerlib-dotnet-grpc-v1/ \
--plugin=protoc-gen-csharp_grpc=/Users/loite/.nuget/packages/grpc.tools/2.76.0/tools/macosx_x64/grpc_csharp_plugin \
Comment on lines 31 to 40
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 script contains hardcoded paths to protoc plugins, which makes it non-portable and specific to a single user's machine (/Users/loite/...). This will cause the script to fail for other developers or in CI/CD environments.

To improve this, consider one of the following approaches:

  1. Rely on PATH: Require developers to have the protoc-gen-* executables in their PATH.
  2. Use Environment Variables: Allow developers to specify the path to the plugins via environment variables.
  3. Local Installation: Add a step to download and install the required plugins locally within the project or use a package manager that handles this.

Expand All @@ -24,7 +43,7 @@ protoc \
--csharp_grpc_opt=no_server \
--proto_path=. \
google/spannerlib/v1/spannerlib.proto

cd .. || exit 1
rm googleapis/google/spannerlib
git rm googleapis -f
rm ../../.gitmodules
echo "Code generation complete for Go, Java, and C#."
echo "Node.js will use dynamic loading via @grpc/proto-loader."
32 changes: 32 additions & 0 deletions spannerlib/wrappers/spannerlib-nodejs-poc/ipc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Spanner NodeJS gRPC/IPC Wrapper

This directory contains a proof-of-concept for a NodeJS wrapper for the Go Spanner library that uses IPC via a gRPC client to communicate with a Go gRPC server.

## Architecture

The wrapper consists of three main parts:

1. **Go gRPC Server**: A server written in Go that exposes the Spanner library's functionality over a gRPC interface. This server is located in `spannerlib/grpc-server`. It must be running for this wrapper to function.

2. **Node.js gRPC Client**: A client written in Node.js that communicates with the Go gRPC server. It uses the `@grpc/grpc-js` and `@grpc/proto-loader` packages to interact with the server. The client is defined in `src/grpc/`.

3. **JavaScript Wrapper**: A high-level JavaScript API that provides `Pool`, `Connection`, and `Rows` classes. This abstracts away the gRPC communication and provides a clean, async/await-based interface that is identical to the Koffi and N-API POCs.

## How to Run

1. **Start the Go gRPC server**:
```sh
cd spannerlib/grpc-server
go run server.go localhost:50051 tcp
```

2. **Install Node.js dependencies**:
```sh
cd spannerlib/wrappers/spannerlib-nodejs-poc/ipc
npm install
```

3. **Run the test**:
```sh
npm test
```
3 changes: 3 additions & 0 deletions spannerlib/wrappers/spannerlib-nodejs-poc/ipc/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module ipc-poc

go 1.25.0
9 changes: 9 additions & 0 deletions spannerlib/wrappers/spannerlib-nodejs-poc/ipc/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { Pool } = require('./src/lib/pool.js');
const { Connection } = require('./src/lib/connection.js');
const { Rows } = require('./src/lib/rows.js');

module.exports = {
Pool,
Connection,
Rows
};
Loading
Loading