FeathersJS API + Firebase实时数据库

jgwigjjp  于 2022-12-19  发布在  其他
关注(0)|答案(1)|浏览(114)

我想如果有办法使用一个Firebase实时数据库与Sequelize的API。
在sequelize.js中,我的API是用本地mariadb设置的:

const Sequelize = require('sequelize');

module.exports = function (app) {
  const sequelize = new Sequelize(
    'dbName',
    'username',
    'password',
     {
       host: 'mariadb',
       dialect: 'mysql'
     }
   );
  const oldSetup = app.setup;

  app.set('sequelizeClient', sequelize);

  app.setup = function (...args) {
    const result = oldSetup.apply(this, args);

    // Set up data relationships
    const models = sequelize.models;
    Object.keys(models).forEach(name => {
      if ('associate' in models[name]) {
        models[name].associate(models);
      }
    });

    // Sync to the database
    app.set('sequelizeSync', sequelize.sync());

    return result;
  };
};

我需要这里的一切尤其是人际关系。
所以我可以使用实时数据库/firestore数据库与羽毛JS续集?

/node_modules/feathers-sequelize/lib/index.js:31
2022-12-08 12:15:50       Sequelize = options.Model.sequelize.Sequelize;
2022-12-08 12:15:50                                           ^
2022-12-08 12:15:50 
2022-12-08 12:15:50 TypeError: Cannot read properties of undefined (reading 'Sequelize')

我从实时数据库中得到的唯一东西是databaseURL,或者也许我应该使用SDK?

whhtz7ly

whhtz7ly1#

也许可以尝试将代码编辑为:

// const Sequelize = require('sequelize');  //remove this
const sequelize = require("firestore-sequelize"); //replace with this
const admin = require("firebase-admin");

module.exports = function (app) {
  //   const sequelize = new Sequelize(
  //     'dbName',
  //     'username',
  //     'password',
  //      {
  //        host: 'mariadb',
  //        dialect: 'mysql'
  //      }
  //    );

  admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
  });
  
  sequelize.initializeApp(admin)
  
  const oldSetup = app.setup;

  app.set("sequelizeClient", sequelize);

  app.setup = function (...args) {
    const result = oldSetup.apply(this, args);

    // Set up data relationships
    const models = sequelize.models;
    Object.keys(models).forEach((name) => {
      if ("associate" in models[name]) {
        models[name].associate(models);
      }
    });

    // Sync to the database
    app.set("sequelizeSync", sequelize.sync());

    return result;
  };
};

至于身份验证/凭据read,这是第一次,因为谷歌必须识别你,并允许访问。

相关问题