typeorm-adapter
typeorm-adapter copied to clipboard
use ExistentConnection
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!
@Shivansh-yadav13
/cc @nodece @Zxilly
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
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.
@Shivansh-yadav13
Closed as resolved