Open RihanArfan opened 1 week ago
Hey @RihanArfan
We indeed imagined the ability to switch between bindings but I did not want to make it too complex to start with, it's very rare the need for multiple databases / KV / R2 and also it may also complexify the admin.
But if we have to work on it, I would see it this way:
export default defineNuxtConfig({
hub: {
database: {
// alias: BINDING
default: 'DB', // always added
users: 'USERS'
}
},
})
Then you can do:
const db = hubDatabase() // default
const usersDb = hubDatabase('users')
We should not have to specify any ID as NuxtHub should take care of this for us.
Hey @Atinux,
Your proposal looks really good to me. I just wanted to add some notes because I think there are definitely use cases where it makes sense to have multiple D1 instances, for example. Since D1 has a maximum limit of 10 GB (see D1 Limit Documentation), it might be useful to split data into multiple databases. Another use case could be to use one database for each customer in an application.
@nicogenz the main issue for having a use case as "one database for each user" is that you cannot add new database at runtime and you actually need to rebuild your website for the bindings to take effect.
Is your feature request related to a problem? Please describe. Right now NuxtHub adds a single binding for whatever feature is enabled in the config with a hardcoded binding name.
Describe the solution you'd like It would be nice if an array could be specified alongside the boolean to allow multiple bindings, and access them by specifying them within the
hubX()
util.Describe alternatives you've considered N/A
Additional context Cloudflare support multiple bindings and for more complex applications, several may be beneficial.