kossnocorp / typesaurus

🦕 Type-safe TypeScript-first ODM for Firestore
https://typesaurus.com
415 stars 36 forks source link

How can I choose a custom database ID instead of the (default) one? #126

Closed keval6706 closed 8 months ago

keval6706 commented 9 months ago
Gets the named {@link https://googleapis.dev/nodejs/firestore/latest/Firestore.html | Firestore}
service for the default app.
Get the Firestore service for a named database and default app

const otherFirestore = getFirestore('otherDb');

@param databaseId - name of database to return.
@returns The named {@link https://googleapis.dev/nodejs/firestore/latest/Firestore.html | Firestore}
service for the default app.
@beta

export declare function getFirestore(databaseId: string): Firestore;
kossnocorp commented 8 months ago

Hey, @keval6706, sorry for the silence. I was on vacation. You can specify the app name when creating the schema: https://typesaurus.com/api/schema/#app

schema(
  ($) => ({
    // ...
  }),
  // Use app-name app at both client and server
  { app: "app-name" },
);

schema(
  ($) => ({
    // ...
  }),
  {
    // Use server-name app at server
    server: { app: "server-name" },
    // Use client-name app at client
    client: { app: "client-name" },
  },
);

Please let me know if it helps or if you have further questions.

mailaneel commented 7 months ago

databaseId is second param to getFirestore, without this it always uses (default) database https://github.com/kossnocorp/typesaurus/blob/7976747ddfa726350d751e7b31894d31f76f3646/src/adapter/admin/firebase.mjs#L15