
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@proteinjs/db-driver-spanner
Advanced tools
Follow these steps to setup a development Spanner database for your app.
cat your-app-abcde123456.json | base64
Keep the string that is returned to save as an environment variable on your machine.nano ~/.zshrc
Add these two lines:
export DEV_DB_NAME="name-of-your-dev-db"
export GCP_SPANNER_SA_KEY="paste the long string that you retrieved from encoding here"DefaultDbDriverFactory is a convenience api for setting the default driver instantiated within Protein Js' Db. You do not need to explicitly register DbDriverFactory anywhere; the Protein Js dependency injection system Reflection handles that automatically. Alternatively, you can instantiate Db with a SpannerDriver manually.import { DbDriver, DefaultDbDriverFactory } from '@proteinjs/db';
import { SpannerDriver } from '@proteinjs/db-driver-spanner';
export class DbDriverFactory implements DefaultDbDriverFactory {
getDbDriver(): DbDriver {
const devDbName = process.env.DEV_DB_NAME;
if (!devDbName) {
throw new Error('Unable to instantiate SpannerDriver. The DEV_DB_NAME environment variable is not set.');
}
const encodedCredentials = process.env.GCP_SPANNER_SA_KEY;
if (!encodedCredentials) {
throw new Error('Unable to instantiate SpannerDriver. The GCP_SPANNER_SA_KEY environment variable is not set.');
}
const credentials = JSON.parse(Buffer.from(encodedCredentials, 'base64').toString('utf-8'));
return new SpannerDriver({
projectId: 'your-project-id',
instanceName: 'your-instance-name',
databaseName: devDbName,
spannerOptions: {
credentials,
},
});
}
}
Follow these steps to setup a test Spanner Database to be used with running automated tests for code that interacts with a Spanner database.
docker pull gcr.io/cloud-spanner-emulator/emulator
docker run -p 9010:9010 -p 9020:9020 gcr.io/cloud-spanner-emulator/emulator
gcloud config configurations create emulator
gcloud config set auth/disable_credentials true
gcloud config set project proteinjs-test
gcloud config set api_endpoint_overrides/spanner http://localhost:9020/
gcloud config configurations activate [emulator | default]gcloud spanner instances create proteinjs-test \
--config=emulator-config --description="Protein JS Test Instance" --nodes=1
gcloud spanner databases create test --instance=proteinjs-test
gcloud spanner databases execute-sql test \
--instance='proteinjs-test' \
--sql='select table_name from information_schema.tables'
Follow these steps to setup a production Spanner database for your app. This assumes you already implemented Dev Environment Setup above.
DbDriverFactory implementation to use different drivers based on environemnt.import { DbDriver, DefaultDbDriverFactory } from '@proteinjs/db';
import { SpannerDriver } from '@proteinjs/db-driver-spanner';
export class DbDriverFactory implements DefaultDbDriverFactory {
getDbDriver(): DbDriver {
if (process.env.DEVELOPMENT) { // or however you check environment
const devDbName = process.env.DEV_DB_NAME;
if (!devDbName) {
throw new Error('Unable to instantiate SpannerDriver. The DEV_DB_NAME environment variable is not set.');
}
const encodedCredentials = process.env.GCP_SPANNER_SA_KEY;
if (!encodedCredentials) {
throw new Error('Unable to instantiate SpannerDriver. The GCP_SPANNER_SA_KEY environment variable is not set.');
}
const credentials = JSON.parse(Buffer.from(encodedCredentials, 'base64').toString('utf-8'));
return new SpannerDriver({
projectId: 'your-project-id',
instanceName: 'your-instance-name',
databaseName: devDbName,
spannerOptions: {
credentials,
},
});
}
const prodDbName = process.env.PROD_DB_NAME;
if (!prodDbName) {
throw new Error('Unable to instantiate SpannerDriver. The PROD_DB_NAME environment variable is not set.');
}
const encodedCredentials = process.env.GCP_SPANNER_SA_KEY;
if (!encodedCredentials) {
throw new Error('Unable to instantiate SpannerDriver. The GCP_SPANNER_SA_KEY environment variable is not set.');
}
const credentials = JSON.parse(Buffer.from(encodedCredentials, 'base64').toString('utf-8'));
return new SpannerDriver({
projectId: 'your-project-id',
instanceName: 'your-instance-name',
databaseName: prodDbName,
spannerOptions: {
credentials,
},
});
}
}
FAQs
Db driver for Google Spanner
We found that @proteinjs/db-driver-spanner demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.