bookshelf without knex - execute query - node.js

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.

Related

Query another database using Prisma

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

How mongoose schema relates to db in CRUD operations

How does fetching records from mongoose find() and updating records with updateOne work exactly.
I am unable to find it on social media..
When a GET request arrived to route handler. Will data fetch from db and maps to schema or will it get records directly from db?
Please explain the proper workflow. What happen when request arrives and how the mapping from db to schema works in CRUD?
Making the assumption that you are also using a framework like expressjs, a GET request does not go directly to mongodb
within a framework like express, you write a handler to handle GET/POST/PATCH/DELETE/PUT etc. within each of those routes you would write your code to interact with mongoose (mongodb)
for reference here is a
basic entry level NODEJS app

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

Which is the best way to do database search on mean stack

I am using mongodb to store items for an auction site
I want to enable fuzzy searching.
Should I query for 1000 results with no parameters then use a js library like fuse.js
Or should I rely on mongodb $regex alone to do the query?
mongodb isn't a great choice for a problem like this. There are lots of great text search utilities available, the most prominent these days being elasticsearch. You'd continue to store your data in mongodb, but you'd keep an elasticsearch instance synced to the mongodb database and perform your searches against elasticsearch. Mongoosastic is a good way to write to both concurrently or Transporter can be used shift the synchronization away from your database persistence flow.
Mongoosastic example:
https://blog.cloudboost.io/sync-mongo-with-elastic-and-save-months-of-development-time-and-cost-d281e0ca8fe4
Some other ways to sync including Transporter: https://code.likeagirl.io/5-different-ways-to-synchronize-data-from-mongodb-to-elasticsearch-d8456b83d44f

Resources