Query another database using Prisma - node.js

I am already using Prisma as an ORM for a Postgres DB. I need to run a simple raw query on a SQL Server DB. I do not need to use any of the ORM features like the Prisma schema, migrations, etc. Is it possible to do with Prisma? I am trying to minimize dependencies.

Look at this part of the documentation and see if it meets your request.
https://www.prisma.io/client
prima raw query

You would need to create two PrismaClient Instances, one for the PostgresDB and other for SQL Server.
Here's a GitHub Issue on how you can implement it: #2443

Related

How to include MYSQL database to github repository for a job recruiter?

I have a node express api and I am planning to use MYSQL or Mongo db and probably sequelize.
I want to include DB schema or some file to recreate database when run dev script, so that job recruiter can replicate empty database (only empty tables).
Whats the usual way of doing this?
Please provide an in-depth answer, how to achieve this!

How to use ORM for NodeJS

I have my SQL Server database - how should I use model query instead of raw query in node js express framework. Is there any way that we can create models for the tables and fetch the result?
ORMs or Object Relational Models are used to interact and perform CRUD operations on a DB server without writing out raw query.
Sequelize is a pretty good ORM for SQL databases in node.js
Read the documentation or checkout a video on youtube on how to create models in Sequelize
Official Website:
https://sequelize.org/
NPM page:
https://www.npmjs.com/package/sequelize

Sequelize: preview sync query without executing it

I'm trying to make an application with node.js and sequelize ORM. I learnt about the function Sequelize.sync() to update database schema based on the app model.
Is there a way to log the SQL statements that Sequelize.sync() would run without executing them?
I'm used to Doctrine ORM where such a thing is possible and quite convenient (it allows to double-check your model before actually persisting it to the DB).
Is there a way to do it with sequelize too?
Thanks

bookshelf without knex - execute query

I have a functioning node.js application with logs data to a mysql database. (without using knex.js)
Now, I want to add functionality to query into my database tables. My question is do I now need knex.js? Is it possible to execute queries without knex?
I could not clearly find examples of this.
From the main Bookshelf page:
Bookshelf is a JavaScript ORM for Node.js, built on the Knex SQL query builder. Featuring both promise based and traditional callback interfaces, it follows the Model & Collection patterns seen in Backbone.js, providing transaction support, eager/nested-eager relation loading, polymorphic associations, and support for one-to-one, one-to-many, and many-to-many relations.
Bookshelf requires a knex connection to operate. You cannot (nor should you) use Bookshelf without Knex.

How do I use flask Migrate and SQLAlchemy on my own database, and connect to a third party database that I do not wish to migrate?

I have discovered a way to connect to multiple databases with Flask through binds.
Facts leading up to question:
I have defined my own database Models with SQLAlchemy.
I use Flask-Migrate to generate my database
I wish to connect to a third party database and use the SQLAlchemy ORM.
I wish to query the third party database using the SQLAlchemy ORM in a way such as: db.session.query(THIRDPARTYMODEL).filter_by(id=id)
I'm worried, that once I define the new models and use Flask Migrate, that it will try to create a new migration and create the tables I already have.
I wish to use my own database and the third party database at the same time.
How can I connect to the third party database and query it using the SQLAchemy ORM without worrying about Flask Migrate trying to generate new tables on the third party database?
Flask-Migrate does not automatically migrate multiple databases, the default is to only migrate the main database from Flask-SQLAlchemy.
The problem is that if you have additional models created that belong to another database, Alembic will consider them part of that main database, so it will write migrations for your main database that include the entire set of models.
To have things working the way you want, you will need to ensure those other models that do not belong in the main database are not imported when you invoke the manage.py db ... set of commands.
You may also tell Flask-Migrate and Alembic to support migrating multiple databases by using flask db init --multidb when initializing the migrations.
I have the same issue, but I wasn't able to use the accepted include_object solution because that method is called too far into the migration on the non-migrated database. In my case, the user doesn't have write access, so the migration failed as soon as Alembic tried to make the alembic_version table on the remote DB. This happened before include_object was called on any of the tables.
Instead, because I wanted Alembic to completely ignore this database and all its tables, I simply put the read-only database in SQLALCHEMY_BINDS and then removed it in migrations/env.py before it was processed:
# ===Generated code===
bind_names = []
for name, url in current_app.config.get("SQLALCHEMY_BINDS").items():
context.config.set_section_option(name, "sqlalchemy.url", url.replace(
'%', '%%'))
bind_names.append(name)
# ===New code===
### Remove the 'remote' bind, which is a read-only database that we don't
### want to track migration changes on.
if 'remote' in bind_names:
bind_names.remove('remote')

Resources