vercel / storage Goto Github PK
View Code? Open in Web Editor NEWVercel Postgres, KV, Blob, and Edge Config
Home Page: https://vercel.com/storage
License: Apache License 2.0
Vercel Postgres, KV, Blob, and Edge Config
Home Page: https://vercel.com/storage
License: Apache License 2.0
Platform: linux
Arch: x64
Version: #202303130630~1681329778~22.04~d824cd4 SMP PREEMPT_DYNAMIC Wed A
Binaries:
Node: 18.15.0
npm: 9.5.0
Yarn: 1.22.19
pnpm: 7.29.0
Relevant packages:
next: 13.4.0
eslint-config-next: 13.4.0
react: 18.2.0
react-dom: 18.2.0
generateStaticParams
on a server component page app/[id]/yourpage.tsx
using a edge-config SDK function, in my case the get
callWhen building a static page in Nextjs with generateStaticParams
that uses the edge-config SDK it spits out the following error
error - Error: @vercel/edge-config: Network error
at eval (webpack-internal:///(sc_server)/./node_modules/@vercel/edge-config/dist/index.node.js:46:23)
at async Layout (webpack-internal:///(sc_server)/./app/sites/[site]/layout.tsx:25:20) {
digest: undefined
}
null
I expect the edge-config SDK to not spit out an error. For now as a work around I have opted out from using the SDK client and go with the Vercel REST API for now as it seems to be working as expected https://edge-config.vercel.com/your_edge_config_id_here/item/example_key_1?token=your_edge_config_read_access_token_here
I have a utils-server.ts
file:
import { kv } from "@vercel/kv";
import "server-only";
export const getLastVisitorLocation = async () => kv.get("lastVisitorLocation");
My root layout calls this function to prepopulate some global state:
export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
/* Get last visitor location for server-side rendering */
/* This is overwritten on hydration, but it's better than starting blank */
const lastVisitorLocation = await getLastVisitorLocation();
console.log(`Last visitor location SSR: ${lastVisitorLocation}`);
When I navigate from a static page to a dynamic page, I get this error:
I can directly load the page, and it works. But when navigating from one page to another, it breaks.
When creating new migrations after having created the first one already, Prisma errors because the database schema isn't empty. This is because Prisma needs a separate database to be used as a shadow database. While it's not a bug per se, it's still a limitation in Vercel since you can only connect one Postgres storage per project environment. To work around this you'd have to create another Postgres storage and manually set a new environment variable to be used as shadowDatabaseUrl
.
Error: P3005
The database schema is not empty. Read more about how to baseline an existing production database: https://pris.ly/d/migrate-baseline
Steps to reproduce:
prisma migrate dev
on a fresh Vercel Postgres storageusers
modelprisma migrate dev
againCannot use sdk's get method on Vite @^3.0.8 as it defaults to process.env.EDGE_CONFIG.
Instead it should accept a parameter for edge config, OR support Vite bundler.
Code example:
import { get } from '@vercel/edge-config';
export const config = { matcher: '/welcome' };
export function middleware(): Promise<any> {
try {
return get('greeting').then((res: any) => res.json());
} catch (error) {
console.log(error);
return Promise.resolve(false);
}
}
Error when trying to call middleware function:
ReferenceError: process is not defined
I'm guessing it happens when we try to read EDGE_CONFIG var key in the init function in index.edge.ts file:
// lazy init fn so the default edge config does not throw in case
// process.env.EDGE_CONFIG is not defined and its methods are never used.
function init(): void {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!defaultEdgeConfigClient) {
defaultEdgeConfigClient = createClient(process.env.EDGE_CONFIG);
}
}
How to reproduce:
Proposed fix for the init function:
Update the init function:
// lazy init fn so the default edge config does not throw in case
// process.env.EDGE_CONFIG is not defined and its methods are never used.
function init(edgeConfig: string): void {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!defaultEdgeConfigClient) {
defaultEdgeConfigClient = createClient(edgeConfig);
}
}
Update the get function and so on.... Ill gladly make a PR with the fix if you guys think it makes sense.
SvelteKit (and Vite) can load environment variables from a .env
file in development mode. SvelteKit makes those available through $env/dynamic/private
, $env/static/private
.
I am adding the KV_REST_API_URL
and KV_REST_API_TOKEN
together with my other environment variables inside the .env
file.
When importing @vercel/kv
, it assumes that the KV_REST_API_URL
and KV_REST_API_TOKEN
are present in the actual environment (through process.env
).
In dev mode with SvelteKit, these variables are not loaded into the environment, and need to be imported. This creates an error when trying to import @vercel/kv
. (Missing required environment variables).
The workaround would be to import { createClient } from '@vercel/kv'
and manually construct the proxy object, but somehow this also fails with the same environment error:
import { createClient } from '@vercel/kv'
import { KV_REST_API_TOKEN, KV_REST_API_URL } from '$env/static/private'
const kv = createClient({
url: KV_REST_API_URL,
token: KV_REST_API_TOKEN
})
Hello Vercel team, I appreciate your work with the Postgres database within Vercel. It's more straightforward to use than Neon. I have a suggestion for a new feature. Right now, I can't change the width of the columns on the dashboard. Is there a way I can do this? Alternatively, a quick fix could be to allow users to download the data as a CSV file. The current situation is we can't see the full query result on Vercel without using Neon.
I would be great if we can use kysely migrations. That should be achieved by disabling transactions
Currently we have this error
{
error: [VercelPostgresError: VercelPostgresError - 'kysely_transactions_not_supported': Transactions are not supported yet.] {
code: 'kysely_transactions_not_supported',
name: 'VercelPostgresError'
}
I think this could be useful
https://kysely-org.github.io/kysely-apidoc/interfaces/DialectAdapter.html#supportsTransactionalDdl
Hi! We are experiencing an issue in the remote deployment (everything works great locally).
### Error in config/get.ts Error: @vercel/edge-config: Network error
at (node_modules/.pnpm/@[email protected]/node_modules/@vercel/edge-config/dist/index.edge.js:1:1102)
at (pages/api/config/get.ts:33:24)
at (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/next/dist/esm/server/web/adapter.js:103:0)
It happens on any interaction with the edge config client. Env. variables are configured correctly, they were connected through Vercel dashboard.
Thanks!
TypeError: Class extends value #<Object> is not a constructor or null
at (index.mjs:7:269795)
at (__nitro:middleware.js:1:17)
Currently I think the edge
runtime is not supported, right?
I am facing na issue trying to connect to my Vercel Postgres DB using Prisma ORM.
$ yarn prisma migrate deploy
yarn run v1.22.19
$ C:\Users\User\Desktop\dream-factory-hr\node_modules\.bin\prisma migrate deploy
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database
Error: Connection url is empty. See https://www.prisma.io/docs/reference/database-reference/connection-urls
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
My schema.prisma file connection string sections look like this:
datasource db {
provider = "postgresql"
url = env("POSTGRES_PRISMA_URL")
directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
shadowDatabaseUrl = env("POSTGRES_URL_NON_POOLING") // used for migrations
}
And my .env file has:
POSTGRES_URL="postgres://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
POSTGRES_URL_NON_POOLING="postgres:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxb"
POSTGRES_PRISMA_URL="postgres://xxxxxxxxxxxxxxxxxxxxxxxxxx"
POSTGRES_USER="xxxx"
POSTGRES_HOST="xxxxxxxx"
POSTGRES_PASSWORD="passwordx"
POSTGRES_DATABASE="databasex"
The other issue is that, Prisma seems to read from .env file and not .env.development.local or .env.local .
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are currently rate-limited. Click on a checkbox below to force their creation now.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
eslint-config-turbo
, turbo
)These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.
.github/workflows/integration-tests-dev.yml
actions/checkout v4
pnpm/action-setup v2
actions/setup-node v4
actions/cache v4
actions/upload-artifact v4
.github/workflows/integration-tests-live.yml
actions/checkout v4
pnpm/action-setup v2
actions/setup-node v4
actions/cache v4
patrickedqvist/wait-for-vercel-preview v1.3.1
actions/upload-artifact v4
.github/workflows/quality.yml
actions/checkout v4
pnpm/action-setup v2
actions/setup-node v4
actions/checkout v4
pnpm/action-setup v2
actions/setup-node v4
actions/checkout v4
pnpm/action-setup v2
actions/setup-node v4
actions/checkout v4
pnpm/action-setup v2
actions/setup-node v4
.github/workflows/release-snapshot.yaml
actions/checkout v4
pnpm/action-setup v2
actions/setup-node v4
.github/workflows/release.yml
actions/checkout v4
pnpm/action-setup v2
actions/setup-node v4
changesets/action v1
.github/workflows/unit-tests.yml
actions/checkout v4
pnpm/action-setup v2
actions/setup-node v4
.github/workflows/visual-tests-schedule.yml
actions/checkout v4
pnpm/action-setup v2
actions/setup-node v4
actions/cache v4
masci/datadog v1
masci/datadog v1
actions/upload-artifact v4
.node-version
package.json
@changesets/cli 2.27.1
@vercel/style-guide 5.2.0
eslint 8.56.0
husky 9.0.11
jest 29.7.0
lint-staged 15.2.2
prettier 3.2.5
publint 0.2.7
ts-jest 29.1.2
turbo 1.12.4
typescript ^5.3.3
node >=18
pnpm 8.15.3
packages/blob/package.json
async-retry ^1.3.3
bytes ^3.1.2
is-buffer ^2.0.5
undici ^5.28.4
@edge-runtime/jest-environment 2.3.10
@edge-runtime/types 2.2.9
@types/async-retry 1.4.8
@types/bytes 3.1.4
@types/jest 29.5.12
@types/node 20.11.19
eslint 8.56.0
jest 29.7.0
jest-environment-jsdom 29.7.0
ts-jest 29.1.2
tsup 8.0.2
node >=16.14
packages/edge-config-fs/package.json
packages/edge-config/package.json
ts-essentials 9.4.1
@changesets/cli 2.27.1
@edge-runtime/jest-environment 2.3.10
@edge-runtime/types 2.2.9
@types/jest 29.5.12
@types/node 20.11.19
eslint 8.56.0
jest 29.7.0
jest-fetch-mock 3.0.3
node-domexception 2.0.1
prettier 3.2.5
ts-jest 29.1.2
tsup 8.0.2
typescript 5.3.3
@opentelemetry/api ^1.7.0
node >=14.6
packages/kv/package.json
@upstash/redis 1.25.2
@changesets/cli 2.27.1
@edge-runtime/jest-environment 2.3.10
@edge-runtime/types 2.2.9
@types/jest 29.5.12
@types/node 20.11.19
eslint 8.56.0
husky 9.0.11
jest 29.7.0
lint-staged 15.2.2
prettier 3.2.5
ts-jest 29.1.2
tsup 8.0.2
typescript 5.3.3
node >=14.6
packages/postgres-kysely/package.json
@changesets/cli 2.27.1
@edge-runtime/jest-environment 2.3.10
@edge-runtime/types 2.2.9
@neondatabase/serverless 0.7.2
@types/jest 29.5.12
@types/node 20.11.19
@types/ws 8.5.10
eslint 8.56.0
jest 29.7.0
kysely 0.27.2
ts-jest 29.1.2
tsup 8.0.2
typescript 5.3.3
kysely ^0.24.2 || ^0.25.0 || ^0.26.0 || ^0.27.0
node >=14.6
packages/postgres/package.json
@neondatabase/serverless 0.7.2
bufferutil 4.0.8
utf-8-validate 6.0.3
ws 8.14.2
@changesets/cli 2.27.1
@edge-runtime/jest-environment 2.3.10
@edge-runtime/types 2.2.9
@types/jest 29.5.12
@types/node 20.11.19
@types/ws 8.5.10
eslint 8.56.0
jest 29.7.0
prettier 3.2.5
ts-jest 29.1.2
tsup 8.0.2
typescript 5.3.3
node >=14.6
tooling/eslint-config-custom/package.json
@vercel/style-guide 5.2.0
eslint 8.56.0
eslint-config-turbo 1.11.2
typescript 5.3.3
tooling/tsconfig/package.json
@vercel/style-guide 5.2.0
eslint 8.56.0
typescript 5.3.3
I added support for @vercel/postgres in authjs-adapter-sql.
It works, but I had to use the webSocketConstructor of the neon driver to get it working in Jest:
https://github.com/roelandmoors/authjs-adapter-sql/blob/main/tests/vercel.test.ts#L9
I also found something like this here:
https://github.com/vercel/storage/blob/main/packages/postgres/src/index-node.ts
Maybe @vercel/postgres should allow setting the websocket constructor directly?
Or is there a better solution?
Dear Vercel team,
I wanted to take a moment to express my appreciation for the remarkable SDK you've developed. It has been a pleasure using it in my current project.
As I've been integrating KV storage into my application, I've noticed its impressive efficiency. However, I've encountered a common scenario where querying by more than just the key becomes necessary. This is where Redis and its FT commands shine. I was wondering if there are any plans to incorporate features such as FT.CREATE and FT.SEARCH into the SDK?
I hope I've provided enough context for my request. If you require any additional information, please don't hesitate to let me know. Thank you for your attention and for creating such a valuable tool.
I am using @vercel/postgres
with drizzle-orm
in my project. Everything works fine when I run my project on localhost, but when I try to use the deployed online version, the following error was throwed whenever I try to perform any db operations:
TypeError: The "listener" argument must be of type Function. Recei ved type function
at checkListener (/var/task/vercel/path0/apps/web/dist/index.cjs:162444:12)
at _addListener (/var/task/vercel/path0/apps/web/dist/index.cjs:162462:15)
at hn.addListener (/var/task/vercel/path0/apps/web/dist/index.cjs:162469:79)
at new Connection (/var/task/vercel/path0/apps/web/dist/index.cjs:163248:21)
at new Client (/var/task/vercel/path0/apps/web/dist/index.cjs:163284:16)
at new NeonClient (/var/task/vercel/path0/apps/web/dist/index.cjs:163591:156)
at new VercelClient (/var/task/vercel/path0/apps/web/dist/index.cjs:163752:20)
at VercelPool.newClient (/var/task/vercel/path0/apps/web/dist/index.cjs:163429:75)
at VercelPool.connect (/var/task/vercel/path0/apps/web/dist/index.cjs:163429:24)
at VercelPool.connect (/var/task/vercel/path0/apps/web/dist/index.cjs:163803:18)
The framwork I'm using is SolidStart. The website is inside a turborepo.
This is my Drizzle setup if it helps:
import {
drizzle,
} from 'drizzle-orm/vercel-postgres'
import {
createPool,
} from '@vercel/postgres'
const client = createPool({
connectionString: process.env.SERVER_DB_URL,
})
export const db = drizzle(client, {
schema,
logger: IS_DEV,
})
I started a project consisting of a single API function that imports @vercel/postgres (import { sql } from '@vercel/postgres';
) where the only package I ever installed with npm was @vercel/postgres (npm i @vercel/postgres). It works on localhost when I run 'vercel dev', but when it is pushed to production on vercel, the API function fails with this error:
2023-07-11T14:55:44.204Z undefined ERROR Cannot find module '/var/task/node_modules/@vercel/postgres/dist/index-node.cjs'
2023-07-11T14:55:44.204Z undefined ERROR Did you forget to add it to "dependencies" in `package.json`?
RequestId: a4dc0c40-e5ff-4a94-befb-dbdc8198d56d Error: Runtime exited with error: exit status 1
Runtime.ExitError
I'm currently trying to set a PostgreSQL session variable in next 13.4.3 using the @vercel/postgres module. I'm trying to use the SET command to set a custom session variable before executing other queries, but I'm encountering an issue.
Here is an example of what I'm trying to do:
const {userId} = auth()
console.log("USERID: ",userId)
await sqlSET request.jwt.claim.uid = ${userId}
;
I'm getting the following error:
error: syntax error at or near "$1"
I found out the hard way that transactions are not yet supported in Kysely/Vercel
Is this on the roadmap?
Maybe add something in the readme that transactions are not yet supported?
beginTransaction(): Promise<void> {
throw new VercelPostgresKyselyError(
'kysely_transactions_not_supported',
'Transactions are not supported yet.',
);
}
The Edge Store Confirm on Vercel will not accept the JSON Below
[
{
"id":226,
"country":"United States",
"country_iso2":"US",
"country_iso3":"USA",
"states":[
{
"id":1,
"state":"Alabama",
"state_abbreviation":"AL",
"country_id":226
},
{
"id":2,
"state":"Alaska",
"state_abbreviation":"AK",
"country_id":226
},
{
"id":3,
"state":"American Samoa",
"state_abbreviation":"AS",
"country_id":226
},
{
"id":4,
"state":"Arizona",
"state_abbreviation":"AZ",
"country_id":226
},
{
"id":5,
"state":"Arkansas",
"state_abbreviation":"AR",
"country_id":226
},
{
"id":6,
"state":"Armed Forces Africa",
"state_abbreviation":"AE",
"country_id":226
},
{
"id":7,
"state":"Armed Forces Americas",
"state_abbreviation":"AA",
"country_id":226
},
{
"id":8,
"state":"Armed Forces Canada",
"state_abbreviation":"AE",
"country_id":226
},
{
"id":9,
"state":"Armed Forces Europe",
"state_abbreviation":"AE",
"country_id":226
},
{
"id":10,
"state":"Armed Forces Middle East",
"state_abbreviation":"AE",
"country_id":226
},
{
"id":11,
"state":"Armed Forces Pacific",
"state_abbreviation":"AP",
"country_id":226
},
{
"id":12,
"state":"California",
"state_abbreviation":"CA",
"country_id":226
},
{
"id":13,
"state":"Colorado",
"state_abbreviation":"CO",
"country_id":226
},
{
"id":14,
"state":"Connecticut",
"state_abbreviation":"CT",
"country_id":226
},
{
"id":15,
"state":"Delaware",
"state_abbreviation":"DE",
"country_id":226
},
{
"id":16,
"state":"District of Columbia",
"state_abbreviation":"DC",
"country_id":226
},
{
"id":17,
"state":"Federated States Of Micronesia",
"state_abbreviation":"FM",
"country_id":226
},
{
"id":18,
"state":"Florida",
"state_abbreviation":"FL",
"country_id":226
},
{
"id":19,
"state":"Georgia",
"state_abbreviation":"GA",
"country_id":226
},
{
"id":20,
"state":"Guam",
"state_abbreviation":"GU",
"country_id":226
},
{
"id":21,
"state":"Hawaii",
"state_abbreviation":"HI",
"country_id":226
},
{
"id":22,
"state":"Idaho",
"state_abbreviation":"ID",
"country_id":226
},
{
"id":23,
"state":"Illinois",
"state_abbreviation":"IL",
"country_id":226
},
{
"id":24,
"state":"Indiana",
"state_abbreviation":"IN",
"country_id":226
},
{
"id":25,
"state":"Iowa",
"state_abbreviation":"IA",
"country_id":226
},
{
"id":26,
"state":"Kansas",
"state_abbreviation":"KS",
"country_id":226
},
{
"id":27,
"state":"Kentucky",
"state_abbreviation":"KY",
"country_id":226
},
{
"id":28,
"state":"Louisiana",
"state_abbreviation":"LA",
"country_id":226
},
{
"id":29,
"state":"Maine",
"state_abbreviation":"ME",
"country_id":226
},
{
"id":30,
"state":"Marshall Islands",
"state_abbreviation":"MH",
"country_id":226
},
{
"id":31,
"state":"Maryland",
"state_abbreviation":"MD",
"country_id":226
},
{
"id":32,
"state":"Massachusetts",
"state_abbreviation":"MA",
"country_id":226
},
{
"id":33,
"state":"Michigan",
"state_abbreviation":"MI",
"country_id":226
},
{
"id":34,
"state":"Minnesota",
"state_abbreviation":"MN",
"country_id":226
},
{
"id":35,
"state":"Mississippi",
"state_abbreviation":"MS",
"country_id":226
},
{
"id":36,
"state":"Missouri",
"state_abbreviation":"MO",
"country_id":226
},
{
"id":37,
"state":"Montana",
"state_abbreviation":"MT",
"country_id":226
},
{
"id":38,
"state":"Nebraska",
"state_abbreviation":"NE",
"country_id":226
},
{
"id":39,
"state":"Nevada",
"state_abbreviation":"NV",
"country_id":226
},
{
"id":40,
"state":"New Hampshire",
"state_abbreviation":"NH",
"country_id":226
},
{
"id":41,
"state":"New Jersey",
"state_abbreviation":"NJ",
"country_id":226
},
{
"id":42,
"state":"New Mexico",
"state_abbreviation":"NM",
"country_id":226
},
{
"id":43,
"state":"New York",
"state_abbreviation":"NY",
"country_id":226
},
{
"id":44,
"state":"North Carolina",
"state_abbreviation":"NC",
"country_id":226
},
{
"id":45,
"state":"North Dakota",
"state_abbreviation":"ND",
"country_id":226
},
{
"id":46,
"state":"Northern Mariana Islands",
"state_abbreviation":"MP",
"country_id":226
},
{
"id":47,
"state":"Ohio",
"state_abbreviation":"OH",
"country_id":226
},
{
"id":48,
"state":"Oklahoma",
"state_abbreviation":"OK",
"country_id":226
},
{
"id":49,
"state":"Oregon",
"state_abbreviation":"OR",
"country_id":226
},
{
"id":50,
"state":"Palau",
"state_abbreviation":"PW",
"country_id":226
},
{
"id":51,
"state":"Pennsylvania",
"state_abbreviation":"PA",
"country_id":226
},
{
"id":52,
"state":"Puerto Rico",
"state_abbreviation":"PR",
"country_id":226
},
{
"id":53,
"state":"Rhode Island",
"state_abbreviation":"RI",
"country_id":226
},
{
"id":54,
"state":"South Carolina",
"state_abbreviation":"SC",
"country_id":226
},
{
"id":55,
"state":"South Dakota",
"state_abbreviation":"SD",
"country_id":226
},
{
"id":56,
"state":"Tennessee",
"state_abbreviation":"TN",
"country_id":226
},
{
"id":57,
"state":"Texas",
"state_abbreviation":"TX",
"country_id":226
},
{
"id":58,
"state":"Utah",
"state_abbreviation":"UT",
"country_id":226
},
{
"id":59,
"state":"Vermont",
"state_abbreviation":"VT",
"country_id":226
},
{
"id":60,
"state":"Virgin Islands",
"state_abbreviation":"VI",
"country_id":226
},
{
"id":61,
"state":"Virginia",
"state_abbreviation":"VA",
"country_id":226
},
{
"id":62,
"state":"Washington",
"state_abbreviation":"WA",
"country_id":226
},
{
"id":63,
"state":"West Virginia",
"state_abbreviation":"WV",
"country_id":226
},
{
"id":64,
"state":"Wisconsin",
"state_abbreviation":"WI",
"country_id":226
},
{
"id":65,
"state":"Wyoming",
"state_abbreviation":"WY",
"country_id":226
}
]
},
{
"id":38,
"country":"Canada",
"country_iso2":"CA",
"country_iso3":"CAN",
"states":[
{
"id":66,
"state":"Alberta",
"state_abbreviation":"AB",
"country_id":38
},
{
"id":67,
"state":"British Columbia",
"state_abbreviation":"BC",
"country_id":38
},
{
"id":68,
"state":"Manitoba",
"state_abbreviation":"MB",
"country_id":38
},
{
"id":69,
"state":"Newfoundland and Labrador",
"state_abbreviation":"NL",
"country_id":38
},
{
"id":70,
"state":"New Brunswick",
"state_abbreviation":"NB",
"country_id":38
},
{
"id":71,
"state":"Nova Scotia",
"state_abbreviation":"NS",
"country_id":38
},
{
"id":72,
"state":"Northwest Territories",
"state_abbreviation":"NT",
"country_id":38
},
{
"id":73,
"state":"Nunavut",
"state_abbreviation":"NU",
"country_id":38
},
{
"id":74,
"state":"Ontario",
"state_abbreviation":"ON",
"country_id":38
},
{
"id":75,
"state":"Prince Edward Island",
"state_abbreviation":"PE",
"country_id":38
},
{
"id":76,
"state":"Quebec",
"state_abbreviation":"QC",
"country_id":38
},
{
"id":77,
"state":"Saskatchewan",
"state_abbreviation":"SK",
"country_id":38
},
{
"id":78,
"state":"Yukon Territory",
"state_abbreviation":"YT",
"country_id":38
}
]
}
]
I'm really interested by your SDK but i've noticed that you need to use an URL and Token from Vercel and i see no option to connect a Redis instance directly.
I'm used to work with local containers for postgres and redis through docker-compose, which is best for many reason including for tests and the ability to work even with a degraded internet connection.
Do you plan to release a docker image for @vercel/kv
or at least a way to connect to a local redis instance ?
Getting the following error in the Vercel function
bind message supplies 4 parameters, but prepared statement "" requires 0
The code:
import { sql, type QueryResult, type QueryResultRow } from "@vercel/postgres"
const addBookmark = async (
id: string,
title: string,
link: string,
icon: string
): Promise<QueryResult<QueryResultRow>> => {
return await sql`INSERT INTO bookmarks(id, title, link, icon) VALUES ('${id}', '${title}', '${link}', '${icon}')`
}
Hi,
Is there any plan to add support for Redis Time Series? https://redis.io/docs/data-types/timeseries/
I know this is an external module but it would be great to have the option to user it.
I'd like to pass a plugin to Kysely, but it looks like that's not possible with the createKysely
function in https://github.com/vercel/storage/blob/main/packages/postgres-kysely/src/index.ts.
I copied the code to my own code base and made the following changes to make it work.
export function createKysely<T>(
poolConfig?: VercelPostgresPoolConfig,
kyselyConfig?: Partial<KyselyConfig>
): Kysely<T> {
return new Kysely<T>({
...kyselyConfig,
dialect: new VercelPostgresDialect({
...poolConfig,
pool: createPool(poolConfig),
}),
});
}
Could this be incorporated into this library?
Hey,
Awesome to see an official Kysely wrapper ❤️
Small correction to the docs though: it seems that Kysely is introduced as an ORM, which it is not. It's a query builder without any concept of relations or models.
When reading the documentation here
The example uses the following code:
await kv.hset(
'userSession',
{ userId: 123, email: '[email protected]' },
{ ex: 100 },
);
However, the current function signature looks it only supports two arguments:
hset: <TData>(key: string, kv: {
[field: string]: TData;
}) => Promise<number>;
version:
"@vercel/kv": "^0.2.2",
Note the
set
function does acceptSetCommandOptions
as the 3rd argument
Hello I was wondering if any Postgres extensions are supported (specifically PostGIS)? If not are there any other solutions that vercel/storage
has for geospatial data lookups?
I thought I could use Vercel Postgres with a local DB for offline development with a custom connection string that points to a local DB...
import { createPool, sql } from '@vercel/postgres';
import { drizzle } from 'drizzle-orm/vercel-postgres';
export const db = drizzle(
process.env.NODE_ENV === 'production'
? sql
: createPool({
connectionString: process.env.POSTGRES_URL,
}),
{ logger: true }
);
...but this doesn't work:
[VercelPostgresError]: VercelPostgresError - 'invalid_connection_string': This connection string is meant to be used with a direct connection. Make sure to use a pooled connection string or try `createClient()` instead.
The initial issue seems to be that the error is triggered if you don't provide a pooled URL, and that check is hardcoded for the presence of -pooler.
in the connection string, due to the URLs Vercel uses:
export function isPooledConnectionString(connectionString: string): boolean {
return connectionString.includes('-pooler.');
}
If I try and bypass this with a local URL like 'postgresql://jschuur:@localhost:5432/learnchineseclub?foo=-pooler.'
then I get a new error:
The database host is 'localhost', which is the default host when none is set. If that's intentional, please ignore this warning. If not, perhaps an environment variable has not been set, or has not been passed to the library?
- error uncaughtException: Error: connect ECONNREFUSED ::1:443
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
digest: undefined
}
Is it currently possible to do local development without using a cloud hosted Vercel Postgres DB in both locations this way? Considering the 1 database limit on the free tier (and low other limits), this makes development rather difficult.
I originally posted this in the Vercel community discussion, but adding here for more visibility. @tcc-sejohnson
I am having trouble doing the following select statement using import { sql } from "@vercel/postgres";
in my NextJs project.
Via CLI (psql) with the following command:
SELECT * FROM Guests WHERE address = '2/105 Seventh Ave, Maylands WA, Australia';
I get this result:
I am unable to use the vercel postgres npm package to retrieve this data programattically in nextjs. I have tried the following examples in NextJs API route with no luck:
const { rows } = await sql`SELECT * FROM Guests WHERE address = ${address};`;
const { rows } = await sql`SELECT * FROM Guests WHERE address = '${address}';`;
error: bind message supplies 1 parameters, but prepared statement "" requires 0
const { rows } = await sql`SELECT * FROM Guests WHERE address = "${address}";`;
error: column "$1" does not exist
const { rows } = await sql`SELECT * FROM Guests WHERE address = '2/105 Seventh Ave, Maylands WA, Australia';`;
const query = "SELECT * FROM Guests WHERE address = '" + address + "';";
console.log(query); // SELECT * FROM Guests WHERE address = '2/105 Seventh Ave, Maylands WA, Australia';
const { rows } = await sql`${query}`;
What is the proper way to use sql
from the SDK to query a table for a row that has a value which has a symbol e.g. addresses with a unit number?
I have also tried:
No response
12/110 Mounts Bay Road,Perth, WA 6000
.import { sql } from "@vercel/postgres";
example docs: https://vercel.com/docs/storage/vercel-postgres/sdkHere's an extract of my postgres db table:
CREATE TABLE my_table(
my_table_id serial PRIMARY KEY,
my_message VARCHAR,
my_date DATE NOT NULL DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'CEST')
)
When I insert into the table, date is correct but time always shows 00:00.
INSERT INTO my_table (my_message) VALUES ('hello world')
INSERT INTO my_table (my_message, my_date) VALUES ('hello world', NOW() AT TIME ZONE 'CEST')
INSERT INTO my_table (my_message, my_date) VALUES ('hello world', CURRENT_TIMESTAMP AT TIME ZONE 'CEST')
Expected behaviour: time saved correctly, both with default value or when using SQL functions on insert.
Operating System:
Platform: linux
Arch: x64
Version: vercel/next.js#1 SMP Fri Jan 27 02:56:13 UTC 2023
Binaries:
Node: 16.18.0
npm: 8.19.2
Yarn: N/A
pnpm: 8.5.1
Relevant packages:
next: 13.4.3-canary.1
eslint-config-next: 13.4.1
react: 18.2.0
react-dom: 18.2.0
typescript: 5.0.4
App directory (appDir: true), Middleware / Edge (API routes, runtime)
https://github.com/Xexr/next_test
Set vercel postgres env vars (ignore the clerk variable)
Install packages with pnpm install
Navigate to http://localhost:3000
Refresh page 10 or so times and you will see that next hangs and the page doesn't refresh.
You can also see the behaviour at: https://next-drizzle-test.vercel.app/
When using the edge runtime with server actions, drizzle and vercel postgres, data fetching/writing eventually causes next to hang after 5-10 times.
I can't work out what exactly is causing the hang, but when I disable the edge runtime and use the node runtime, the issue does not exist.
The issue occurs in both development and when deployed to vercel.
I should be able to fetch data / refresh the page as many times as I like without next hanging.
Brave Version 1.51.114 Chromium: 113.0.5672.92 (Official Build) (64-bit)
Vercel
I have created some functions to read and write data from Postgres database following the example provided in the doc
Also, as per the documentation using db is the most efficient way to interact with the database, but it's hanging the connection after a certain number of calls. I suspect it is something to do with the client pool.
import { db } from "@vercel/postgres";
export async function PhotoViews(photo_id: string) {
const client = await db.connect();
try {
const result =
await client.sql`SELECT COUNT(*) AS COUNT FROM photo_views WHERE photo_id = ${photo_id};`;
return result.rows[0];
} catch (error) {
throw error;
}
}
If I switch my code to use createClient() I don't see the problem. Here is the same function using createClient().
import { createClient } from "@vercel/postgres";
export async function PhotoViews(photo_id: string) {
const client = createClient();
await client.connect();
//const client = await db.connect();
try {
const result =
await client.sql`SELECT COUNT(*) AS COUNT FROM photo_views WHERE photo_id = ${photo_id};`;
return result.rows[0];
} catch (error) {
throw error;
} finally {
client.end();
}
}
If you run:
import { kv } from "@vercel/kv";
const a1 = "a"
await kv.set(url, a1)
const b1 = await kv.get(url)
console.log("test 1")
console.log(typeof a1)
console.log(typeof b1)
const a2 = "1"
await kv.set(url, a2)
const b2 = await kv.get(url)
console.log("test 2")
console.log(typeof a2)
console.log(typeof b2)
const a3 = "{}"
await kv.set(url, a3)
const b3 = await kv.get(url)
console.log("test 3")
console.log(typeof a3)
console.log(typeof b3)
you get:
test 1
string
string
test 2
string
number
test 3
string
object
Should they not all return string
? Is the auto-parsing is the desired behavior? Where is this documented? I couldn't find it here.
Hello,
I am trying to figure out how to do multiple updates to my database at once.
I've got the following code:
let setValues = []
setValues.push(user.name ? `name = "${twoWayEncrypt(user.name)}"` : undefined)
setValues.push(user.email ? `email = "${twoWayEncrypt(user.email)}"` : undefined)
setValues.push(
user.password && user.password !== ''
? `password = "${await oneWayEncrypt(user.password)}"`
: undefined,
)
setValues.push(
user.access_rights ? `access_rights = '${JSON.stringify(user.access_rights)}'` : undefined,
)
setValues = setValues.filter(v => v)
await sql`UPDATE users SET ${setValues.join(', ')} WHERE id = ${user.id};`
Which throws me a syntax error. What would be the correct way to do this sort of thing?
How to use Vercel KV to store and retrieve posts from an API? i have a simple Nodejs express API that retrieves a random post from the Mongodb but how can i use Vercel KV to store and retrieve posts? like first it gives a normal MongoDB response to the user but after that, it starts giving a response from Vercel KV from the cache..
router.get('/posts', async (req, res) => {
try {
const page = Number(req.query.page) || 1;
const limit = Number(req.query.limit) || 50;
const skip = (page - 1) * limit;
const result = await User.aggregate([
{ $project: { posts: 1 } },
{ $unwind: '$posts' },
{ $project: { postImage: '$posts.post', date: '$posts.date' } },
{ $sort: { date: -1 } },
{ $skip: skip },
{ $limit: limit },
]);
res.json(result);
} catch (err) {
console.error(err);
res.status(500).json({ message: 'Internal server error' });
}
});
Vercel KV works when running locally, but not when running from an edge function.
Here's my code:
import { kv } from "@vercel/kv";
//the following is inside an Edge Function:
console.log("keys", await kv.keys("*"));
Ran the following commands:
vercel env pull .env.ssr.local
vite --mode ssr
When I invoke my function, it works just fine and sets the content in the KV store. I can verify this by going to the CLI in the Dashboard and checking that the key is there.
Pushed to my repo.
Had Vercel deploy it.
Verified in the build logs that both the function was deployed and the static assets:
Verified that my database is attached to the project in the dashboard:
After triggering the edge function, it returns an error 500. Viewing the logs yields the following error:
Error: @vercel/kv: Missing required environment variables KV_REST_API_URL and KV_REST_API_TOKEN
at (@qwik-city-plan.js:27:78546)
at (@qwik-city-plan.js:27:85712)
at (assets/index.qwik-cc4e9f9f.js:9:5088)
at (assets/index.qwik-cc4e9f9f.js:13:2233)
at (assets/index.qwik-cc4e9f9f.js:7:1389)
at (assets/index.qwik-cc4e9f9f.js:13:2161)
at (assets/index.qwik-cc4e9f9f.js:13:2394)
at (entry.vercel-edge.js:16:441)
at (entry.vercel-edge.js:20:3149)
at (entry.vercel-edge.js:20:830)
I am using Vercel KV in NextJS getStaticContext
and getStaticPaths
to cache Auth0 client credentials grant access tokens (since Auth0 has monthly limits on the number of machine-to-machine tokens per month per account).
The code is very simple, something like this (this is called from getStaticContext
and getStaticPaths
to obtain access tokens to use for GraphQL calls):
import { kv } from '@vercel/kv';
async clientCredentialsGrant(scope: string | undefined = undefined) {
const env = process.env['VERCEL_ENV'] ?? 'development';
const tokenKvKey = `${env}:m2m-token`;
const cachedResponse = await kv.get<TokenResponse>(tokenKvKey);
if (cachedResponse) return cachedResponse;
const newTokenResponse = await authenticationClient.clientCredentialsGrant({
audience: process.env['AUTH0_AUDIENCE'] as string,
scope: scope
});
// expire slightly early to avoid racing
await kv.setex(tokenKvKey, newTokenResponse.expires_in - 60, newTokenResponse);
return newTokenResponse;
}
Both locally and when deploying to Vercel (I use github actions to run vercel build
and vercel deploy
rather than the vercel git integration), I got fairly frequent errors of the form ""Error [UpstashError]: DB connection refused". The error doesn't happen each time, but it happens quite a bit.
I think it's a foregone conclusion but just want to make sure I did not miss anything. If using CRA, all environment variables must be prefaced with REACT_APP so the no config option will always fail to pick up the required variables i.e. POSTGRES_URL. Is this correct?
Expected Behavior
No error when calling getAll().
Current Behavior
Working fine on dev environment, throws "Expected keys to be an array of string" exception on Vercel deployment.
Possible Solution
https://github.com/vercel/edge-config/blob/9689e9a0e21bba231e802074096a5a338f83c64f/src/index.ts#L257 should be conditioned like on line 265.
I have more than 1 edge config that my application interfaces with.
First question, is there some reason that I am missing that I shouldn't use multiple edge configs? I want to make sure that going this route is not a foot gun.
Second, is there a way for me to change which env var to use for various calls? Something like:
get("faqs", {envVar: process.env.EDGE_CONFIG})
get("faqs", {envVar: process.env.EDGE_CONFIG2})
The original issue was in a different repo vercel/examples#697
I am using ubuntu 20.04, psql was installed via
sudo apt update
sudo apt install postgresql
Verify psql and OS
psql --version
Output
psql (PostgreSQL) 12.14 (Ubuntu 12.14-0ubuntu0.20.04.1)
The Suggested psql connection example in postgres-prisma-postgres does not work:
# Format:
psql "postgresql://username:password@host:port/database"
# Example provided by the console:
psql "postgres://default:************@ep-morning-dust-436279.us-east-1.postgres.vercel-storage.com:5432/verceldb"
It gives this error:
psql: error: ERROR: Endpoint ID is not specified. Either please upgrade the postgres client library (libpq) for SNI support or pass the endpoint ID (first part of the domain name) as a parameter: '?options=project%3D<endpoint-id>'. See more at https://neon.tech/sni
ERROR: connection is insecure (try using `sslmode=require`)
However, this connection string does work, if the endpoint is appended:
# Format:
psql "postgresql://username:password@host:port/database?options=project%3D<endpoint>"
# Example:
psql "postgres://default:************@ep-morning-dust-436279.us-east-1.postgres.vercel-storage.com:5432/verceldb?options=project%3Dep-morning-dust-436279"
Output:
psql (12.14 (Ubuntu 12.14-0ubuntu0.20.04.1), server 15.2)
WARNING: psql major version 12, server major version 15.
Some psql features might not work.
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
verceldb=> \dt
List of relations
Schema | Name | Type | Owner
--------+-------+-------+---------
public | users | table | default
(1 row)
I'm wondering if there are plans to add write/update functionality!
Atm when working w/ Edge Config, I write a light wrapper that re-exports everything in the SDK and additionally implements a patch
function calls https://api.vercel.com/v1/edge-config/${edgeConfigId}/items${teamId ? "?teamId=${teamId}" : ''
with Vercel API token
I had to dig around a little though — the API docs confused me at first, I incorrectly used "Update Edge Config" endpoint first instead of the "Update Edge Config items in batch" 🙈
Obviously it ended up being simple to implement, but would be even nicer if it was part of the SDK with type defs and all that good stuff 😄
In all of our packages, we support no-config on platforms that use process.env
. Vite does not -- it uses import.meta.env
, with a catch. To avoid exposing system env vars to your build process, Vite requires its env vars to be prefixed with VITE_
.
This means, for example, that the following code in Postgres:
export function postgresConnectionString(
type: ConnectionStringType = 'pool',
): string | undefined {
let connectionString: string | undefined;
switch (type) {
case 'pool': {
connectionString = process.env.POSTGRES_URL;
break;
}
case 'direct': {
connectionString = process.env.POSTGRES_URL_NON_POOLING;
break;
}
default: {
const _exhaustiveCheck: never = type;
const str = _exhaustiveCheck as string;
throw new VercelPostgresError(
'invalid_connection_type',
`Unhandled type: ${str}`,
);
}
}
if (connectionString === 'undefined') connectionString = undefined;
return connectionString;
}
could support Vite by doing:
export function postgresConnectionString(
type: ConnectionStringType = 'pool',
): string | undefined {
let connectionString: string | undefined;
switch (type) {
case 'pool': {
- connectionString = process.env.POSTGRES_URL;
+ connectionString = process.env?.POSTGRES_URL ?? import.meta.env?.VITE_POSTGRES_URL;
break;
}
case 'direct': {
- connectionString = process.env.POSTGRES_URL_NON_POOLING;
+ connectionString = process.env?.POSTGRES_URL_NON_POOLING ?? import.meta.env?.VITE_POSTGRES_URL_NON_POOLING;
break;
}
default: {
const _exhaustiveCheck: never = type;
const str = _exhaustiveCheck as string;
throw new VercelPostgresError(
'invalid_connection_type',
`Unhandled type: ${str}`,
);
}
}
if (connectionString === 'undefined') connectionString = undefined;
return connectionString;
}
We could also potentially enhance the error by detecting if the user is running Vite by doing something like:
if (import.meta.env.MODE !== undefined) {
// enhance error with a "You might need to prefix your environment variables with `VITE_`" message
}
One note of caution: The ideal experience here would also require some level of integration with build & deploy + our examples in the storage dashboard. Ideally, connecting a store to a project that's running on Vite would automatically prefix its env vars with VITE_
.
Are streams supported? The documentation is misleading as Redis compatibility page says they are, but then another page has no mention of streams.
In the KV CLI I was able to add into a stream, but I cannot read that data.
CLI fails with
ERR Command is not allowed in REST: "XREAD"
There is no xRead
method in the @vercel/kv
package.
Upstash is showing support for reading from streams, wondering how to access it KV?
Can you provide an early access to vercel/blob?
I successfully deployed a Laravel project and I enabled Postgres
on my project from Vercel. The variables have been set up automatically.
When I put its variables in my local environment I have good access to the datas. On the other hand on the deployed version I get this error:
SQLSTATE[08006] [7] ERROR: Endpoint ID is not specified.
Either please upgrade the postgres client library (libpq) for SNI support or pass the endpoint ID
(first part of the domain name) as a parameter: '?options=project%3D<endpoint-id>'.
This error caught by Laravel seems to come from the Neon API used by Vercel.
Thx,
Jordan
The same sql sentence gets different result between localhost and Vercel's deployment.
See the comment below.
I create a table by Vercel's postgreSQL service throught this:
CREATE TABLE meetings (
id SERIAL PRIMARY KEY,
date_time TIMESTAMP WITHOUT TIME ZONE
);
Then I insert through this:
INSERT INTO meetings (date_time)
VALUES ('2023-08-24 17:00:00');
Blow is what the table looks like in Vercel's web query console:
id | date_time |
---|---|
1 | Thu Aug 24 2023 17:00:00 GMT+0800 (**标准时间) |
Then I query though this:
SELECT date_time FROM meetings
WHERE id=1;
Things goes wrong then:
On my computer localhost, it's:
date_time: 2023-08-24T09:00:00.000Z
On Vercel, the log shows:
date_time: 2023-08-24T17:00:00.000Z,
There are 8 hours distance always, how strange.
Here are my query code (looks like no big problem):
// ...
sql_ = `SELECT meeting_id, date_time, ... WHERE meeting_id IN (SELECT unnest(meetings) FROM users_meetings WHERE id = ${user_id});`;
console.log(sql_);
let meetings = (await client.query(sql_)).rows;
console.log(meetings);
// ...
The result on Vercel's deployment is right while it's wrong on localhost.
Hi,
I'm trying to use edge config on the client side in a NextJS app but i'm getting CORS errors
How to reproduce
just call get
or getAll
method in the browser
import { getAll } from '@vercel/edge-config';
import { useEffect } from 'react';
const MyPage = () => {
useEffect(() => {
console.log(process.env.EDGE_CONFIG);
getAll().then((result) => {
console.log(result);
});
}, []);
return <div>MyPage</div>;
};
export default MyPage;
Environment
Chrome Version 110.0.5481.177 (Official Build) (arm64)
MacOS 13.2.1
We should be using https://www.npmjs.com/package/server-only to signal that our packages can't be used on the client.
This gives a good error when using the packages on the client (which technically works for kv, blob and postgres but should never be done.
When importing @vercel/postgres
from a CommonJS module with "moduleResolution": "Node16"
TypeScript resolves the ES module type declaration so it thinks it is importing an ES module. The result is a compilation error telling you to use a dynamic import.
A better explanation can be found here.
I found this when I tried to use @vercel/postgres
but I'm pretty sure this happens in all packages in this repo.
I think the solution would be to remove the "types"
field in package.json and let TypeScript infer the right file based on the name.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.