npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@decentparadox/typeconnect

v1.0.2

Published

**TypeConnect** is an npm package that simplifies database operations by providing a universal Entity Manager for interacting with both SQLite and PostgreSQL databases. With this package, you can easily define entities using decorators, and perform common

Downloads

201

Readme

TypeConnect

TypeConnect is an npm package that simplifies database operations by providing a universal Entity Manager for interacting with both SQLite and PostgreSQL databases. With this package, you can easily define entities using decorators, and perform common database operations (CRUD) without worrying about the underlying database specifics.

Features

  • Multi-Database Support: Seamlessly supports both SQLite and PostgreSQL databases.
  • Entity and Column Decorators: Use decorators to define tables and columns in your entities.
  • CRUD Operations: Perform create, read, update, and delete operations easily across both SQLite and PostgreSQL.
  • Database Connection Management: Automatically connects and disconnects from the database.
  • Dynamic SQL Queries: Adapts SQL queries to work with both SQLite and PostgreSQL.

Installation

To install TypeConnect, use npm:

npm install @decentparadox/typeconnect

Usage

1. Define an Entity

Use the @Entity and @Column decorators to define your database tables and columns.

import { Entity, Column } from "typeconnect";

@Entity("users")
class User {
  @Column("id")
  id: string;

  @Column("name")
  name: string;

  @Column("email")
  email: string;
}

2. Initialize EntityManager

Create an instance of the EntityManager and connect to your database.

import { EntityManager } from "typeconnect";

// Connect to SQLite (default) or PostgreSQL
const entityManager = new EntityManager(":memory:", "sqlite");

// Connect to PostgreSQL
// const entityManager = new EntityManager("postgres://user:password@localhost:5432/mydb", "postgres");

// Connect to database
await entityManager.connect();

3. Perform CRUD Operations

Use the EntityManager to perform CRUD operations (Create, Read, Update, Delete).

Create Table

await entityManager.createTable(User);

Save an Entity

const user = new User();
user.id = "1";
user.name = "John Doe";
user.email = "[email protected]";

await entityManager.save(user);

Find All Entities

const users = await entityManager.findAll(User);
console.log(users);

Find an Entity by ID

const user = await entityManager.findById(User, "1");
console.log(user);

Update an Entity

const updates = { name: "Jane Doe" };
await entityManager.update(User, "1", updates);

Delete an Entity

await entityManager.delete(User, "1");

4. Disconnect from Database

Once you're done with the database, disconnect it:

await entityManager.disconnect();

Configuration

You can configure TypeConnect to use different database types (SQLite or PostgreSQL) by passing the appropriate values in the constructor.

  • SQLite: Default database type (sqlite)
  • PostgreSQL: Set dbType to "postgres" and provide the connection string.
const entityManager = new EntityManager(":memory:", "sqlite");  // SQLite
const entityManager = new EntityManager("postgres://user:password@localhost:5432/mydb", "postgres");  // PostgreSQL

Advanced Usage

Multiple Entities

You can create multiple entities and manage them using the same EntityManager instance.

Custom SQL Queries

The EntityManager supports dynamically generated SQL queries. You can also add your custom SQL queries if needed.

Future Scope

  • Enhanced Query Builder: Support more complex queries such as JOIN, GROUP BY, and ORDER BY.
  • Support for Other Databases: Expand to support MySQL, MongoDB, and others.
  • ORM Features: Add model validation, migrations, and relationships between entities.
  • Better Error Handling: Improve error logging and handling for complex database interactions.

Contributing

We welcome contributions! If you'd like to contribute to the development of TypeConnect, please fork the repository and create a pull request.

License

MIT License. See LICENSE for more information.