YaDominiosYaDominios

Database and files in your app (env.DB and env.BUCKET)

Updated: 2026-07-18 · YaDominios

Your site on YaDominios Cloud can have a database and file storage. If your repository includes a _worker.js file, we automatically create a database (env.DB) and a file bucket (env.BUCKET); if you include schema.sql, we create your tables. Everything lives in our cloud, with no servers to set up.

How to enable it (for your developer)

A regular site only carries static files. To give it a database and file storage, your repository must include, at the published root:

  • _worker.js — your app's server code. It receives requests and uses env.DB (database) and env.BUCKET (files). Anything that isn't your code, it serves as a site with env.ASSETS.fetch(request).
  • schema.sql (optional) — your database tables; we create them on publish.
  • index.html — your page (the frontend).

Minimal _worker.js example

export default {
  async fetch(req, env) {
    const url = new URL(req.url);
    if (url.pathname === "/data") {
      const { results } = await env.DB.prepare("SELECT * FROM my_table").all();
      return Response.json(results);
    }
    return env.ASSETS.fetch(req); // serves your site
  }
};

⚠️ Don't use the /api/ prefix for your backend routes. On YaDominios Cloud static files are served before your code, and in apps that ship assets (e.g. Next.js/OpenNext) the routing can capture /api/* and return 404 before reaching your worker. Use any other prefix for your endpoints: /data, /media, /upload, etc.

What we give you automatically

  • env.DB — your site's own SQL database on YaDominios Cloud (SQLite engine).
  • env.BUCKET — your site's own file/image storage on YaDominios Cloud.
  • Your environment variables — whatever you saved in the dashboard, available as env.WHATEVER.

You don't have to create anything by hand: when you publish your repo, the database and storage are created automatically and connected to your site. In the dashboard you'll see “Database active” and “Storage active.”

Several databases in the same site

Besides the main one, your site can have more databases with names you choose. Create them in the dashboard, under YaDominios Cloud → your site → Database, and receive them in your code under that name:

const chile  = env.DB_CL;      // Chile's data
const global = env.DB_GLOBAL;  // whatever is shared
const main   = env.DB;         // the main one, always there

Use it to truly separate data that must not mix: one country per database, or the public and private sides of your business. With separate databases, a query that forgets to filter cannot return the other side's data — it isn't in the same place.

Three things worth knowing:

  • The name goes in uppercase and only allows letters, numbers and underscore: DB_CL, DB_GLOBAL. That's what the engine requires.
  • After creating a database, publish your site again. Until then your code can't see it.
  • How many you can have depends on your plan, and the dashboard tells you how many you've used.

To load data from outside, the query API accepts which database you mean: add "base": "DB_CL" to the request body. Without that field, the main one is used.

Frequently asked questions

Do I need to install or configure the database?

No. Just include _worker.js in your repo and we create the database and connect it to your site automatically on publish.

How do I create my tables?

Add a schema.sql file to your repository with your CREATE TABLE statements; we run them on publish.

Can I upload my users' images?

Yes. Every app with a backend gets file storage (env.BUCKET) where you keep images and files, with zero egress cost.

Keep reading

Ready for your domain?

Search for it now and have it live in minutes.

Search my domain