@planetscale/database
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -24,5 +24,6 @@ export { format } from './sanitization.js'; | ||
export interface Config { | ||
username: string; | ||
password: string; | ||
host: string; | ||
url?: string; | ||
username?: string; | ||
password?: string; | ||
host?: string; | ||
fetch?: (input: string, init?: ReqInit) => Promise<Pick<Response, 'ok' | 'json' | 'status' | 'statusText' | 'text'>>; | ||
@@ -29,0 +30,0 @@ format?: (query: string, args: any) => string; |
@@ -18,7 +18,14 @@ import { format } from './sanitization.js'; | ||
constructor(config) { | ||
var _a; | ||
this.session = null; | ||
this.config = { ...config }; | ||
if (typeof fetch !== 'undefined') { | ||
config = { fetch, ...config }; | ||
(_a = this.config).fetch || (_a.fetch = fetch); | ||
} | ||
this.config = config; | ||
this.session = null; | ||
if (config.url) { | ||
const url = new URL(config.url); | ||
this.config.username = url.username; | ||
this.config.password = url.password; | ||
this.config.host = url.hostname; | ||
} | ||
} | ||
@@ -25,0 +32,0 @@ async refresh() { |
{ | ||
"name": "@planetscale/database", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "A JavaScript client for PlanetScale databases.", | ||
@@ -30,3 +30,4 @@ "main": "dist/index.js", | ||
"test": "jest", | ||
"prepublishOnly": "npm run build" | ||
"prepublishOnly": "npm run build", | ||
"postpublish": "npm publish --ignore-scripts --@planetscale:registry='https://npm.pkg.github.com'" | ||
}, | ||
@@ -33,0 +34,0 @@ "repository": { |
@@ -22,3 +22,3 @@ # PlanetScale database client | ||
const conn = await connect(config) | ||
const conn = connect(config) | ||
const results = await conn.execute('select 1 from dual where 1=?', [1]) | ||
@@ -28,2 +28,16 @@ console.log(results) | ||
### Database URL | ||
A single database URL value can be used to configure the `host`, `username`, and `password` values. | ||
```ts | ||
import { connect } from '@planetscale/database' | ||
const config = { | ||
url: process.env['DATABASE_URL'] || 'mysql://user:pass@aws.connect.psdb.cloud' | ||
} | ||
const conn = connect(config) | ||
``` | ||
### Connection factory | ||
@@ -64,3 +78,3 @@ | ||
const conn = await connect(config) | ||
const conn = connect(config) | ||
const results = await conn.execute('select 1 from dual') | ||
@@ -85,3 +99,3 @@ console.log(results) | ||
const conn = await connect(config) | ||
const conn = connect(config) | ||
const results = await conn.execute('select 1 from dual where 1=?', [42]) | ||
@@ -88,0 +102,0 @@ console.log(results) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
24849
283
117
3