typeorm-adapter icon indicating copy to clipboard operation
typeorm-adapter copied to clipboard

use ExistentConnection

Open nobu121 opened this issue 2 years ago • 3 comments

how can i use the ExistentConnection?

  const conn = getConnection();

  const adapter = await TypeORMAdapter.newAdapter({
      connection: conn,
  });

but i got No metadata for "CasbinRule" was found.

please help me, thanks!

nobu121 avatar Jul 20 '22 10:07 nobu121

@Shivansh-yadav13

/cc @nodece @Zxilly

hsluoyz avatar Jul 20 '22 13:07 hsluoyz

I have not used this adapter before, but maybe you need to use the trick written in the test: https://github.com/node-casbin/typeorm-adapter/blob/master/test/existent-connection-adapter.test.ts https://github.com/node-casbin/typeorm-adapter/blob/db31e4e32e9e6664efa515d0700043e960bf6664/test/existent-connection-adapter.test.ts#L55

Shivansh-yadav13 avatar Jul 21 '22 12:07 Shivansh-yadav13

You need to initialize your DB connection (wherever you pass in your credentials) with a entities: [CasbinRule]. There might also be an API to add the metadata afterwords. Another thing is that you need to add a migration or set synchronize=true on your connection in order for the casbin rule table to be added to the database.

jkalberer avatar Jul 29 '22 19:07 jkalberer

@Shivansh-yadav13

hsluoyz avatar Jul 30 '22 15:07 hsluoyz

Closed as resolved

hsluoyz avatar Apr 10 '24 03:04 hsluoyz