⚡ Tired of DB Setups? Meet Swapp: The Universal DB Adapter

Amartya Chowdhury - Feb 9 - - Dev Community

Let's be honest: working with databases can be a pain. Whether its a SQL database like MySQL or PostgreSQL, or a NoSQL one like MongoDB, each has its own syntax, setup and quirks. Using any one of these involves copying and pasting tons of boilerplate code, and dealing with all sorts of dependencies.

And don't even get me started on switching databases, especially from a SQL to a NoSQL one or vice-versa. Learning multiple different ways to write queries for the same basic operations gets annoying, right?

That's where Swapp comes in!

Imagine setting up a database with just one statement, and use one query language for both SQL and NoSQL databases. Sounds like a dream? Well, it just got real!

🚀 Swapp.js is live!

🔗 GitHub Repo | 📦 NPM Package

🚀 Swapp.js just launched on Product Hunt! and Peerlist


Table Of Contents

What is Swapp?

Swapp is an easy-to-use database abstraction layer for Node.js. It connects to both SQL (like Supabase) and NoSQL (like MongoDB) databases using a simple, unified interface. The beauty of Swapp is that it lets you use a universal query language - think SQL-like queries - across both SQL and NoSQL databases. No more changing the entirety of your code just to switch from a SQL to a NoSQL database (or the other way around).

Here's what Swapp provides you with:

  • Skip the tedious database setup process.
  • Write queries in a SQL-like syntax that works across both MongoDB and Supabase (and more databases getting support soon).
  • Focus on building your app, not on configuring your database.
  • Enjoy easy-to-understand API calls for CRUD operations.

Basically, it does the heavy-lifting so you don't have to. Just configure Swapp, and then you can start building your app's features immediately. Swapp will take care of setting up the database for you.

How to use Swapp?

Installation

Installing Swapp is really easy. Just download it from npm, and you're set to go!

npm install swapp.js --legacy-peer-deps
Enter fullscreen mode Exit fullscreen mode

or

yarn add swapp.js
Enter fullscreen mode Exit fullscreen mode

Configuring Your Database

Right now, Swapp supports MongoDB and Supabase. More databases are currently in development.

If you're using MongoDB:

const db = new Swapp({
  provider: 'mongodb',
  config: {
    connectionString: '<mongodb-connection-string>',
    dbName: '<database-name>'
  }
})
Enter fullscreen mode Exit fullscreen mode

In case you use Supabase:

const db = new Swapp({
  provider: 'supabase',
  config: {
    supabaseKey: '<Supabase-Key>',
    supabaseUrl: '<Supabase-URL>'
  }
})
Enter fullscreen mode Exit fullscreen mode

Basic CRUD Operations

Most of the basic CRUD operations work just as expected. For example, to save data to the database:

await db.save('<collection/table name>', {name: "John", age: 25})
Enter fullscreen mode Exit fullscreen mode

Now comes the fun part: the queries. Look at this example:

const data = await db.get('collection/table name', 'WHERE name = "John"')
Enter fullscreen mode Exit fullscreen mode

This searches for entries in the database with name = "John". Classic SQL-like query. The catch? This works seamlessly, whether you're using a SQL database (like Supabase) or a NoSQL one (like MongoDB)!

Similarly, there are functions for db.update() and db.delete() as well. Check out the GitHub repository of Swapp for more detailed documentation.

Why Use Swapp?

If you're still unsure why you should use Swapp when there are so many database packages out there, let me try changing your mind:

  • Save Time: No more memorizing different query languages for different databases. Swapp lets you focus on building your app, instead of worrying about database setups and queries.
  • SQL and NoSQL in One Package: Swapp gives you the flexibility to use both SQL and NoSQL databases. If you wanna try out MongoDB for some flexible data storage and then shift to Supabase for a more structured data, Swapp lets you do that easily by changing just a single statement.
  • Ideal for MVPs and Prototyping: If you're building an MVP or a prototype and don't want to be bogged down by database setup, Swapps lets you just plug in and get started quickly.
  • Simple, Intuitive API: CRUD operations? Check. Universal queries? Check. But still easy to work with. You won't need to read through pages of documentation to get a simple query running.

Conclusion

Swapp is here to make your life easier. Whether you're new to databases or have been wrangling them for years, this tool can save you a ton of time and effort.

So, why not give it a try? You'll be up and running in minutes, and you can spend your valuable time actually building your app.

Check out the GitHub Repository and leave a star if you found Swapp to be actually helpful in your development workflow. Feel free to leave any feedback and suggestions you may have, I am always open to new ideas.

Let's swap out the complexity and start building!

. . .