Convert Figma logo to code with AI

tediousjs logotedious

Node TDS module for connecting to SQL Server databases.

1,570
436
1,570
195

Top Related Projects

:zap: fast mysqljs/mysql compatible mysql driver for node.js

18,264

A pure node.js JavaScript Client implementing the MySQL protocol.

PostgreSQL client for node.js.

19,158

A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.

29,432

Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i.

34,121

ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

Quick Overview

Tedious is a pure JavaScript implementation of the TDS protocol, which is used to interact with Microsoft SQL Server databases. It provides a low-level, high-performance driver for Node.js applications to connect to and query SQL Server and Azure SQL Database.

Pros

  • Pure JavaScript implementation, allowing for easy integration with Node.js projects
  • High performance and efficient memory usage
  • Supports modern SQL Server features and data types
  • Active development and community support

Cons

  • Lower-level API compared to some other SQL Server drivers, which may require more code for basic operations
  • Learning curve for developers not familiar with the TDS protocol
  • Limited built-in connection pooling (though can be used with external connection pool libraries)

Code Examples

  1. Connecting to a database:
const { Connection } = require('tedious');

const config = {
  server: 'localhost',
  authentication: {
    type: 'default',
    options: {
      userName: 'username',
      password: 'password'
    }
  },
  options: {
    database: 'mydatabase',
    encrypt: true
  }
};

const connection = new Connection(config);

connection.on('connect', (err) => {
  if (err) {
    console.error('Connection failed:', err);
  } else {
    console.log('Connected to database');
  }
});

connection.connect();
  1. Executing a simple query:
const { Request } = require('tedious');

const request = new Request("SELECT * FROM Users WHERE Id = @Id", (err, rowCount) => {
  if (err) {
    console.error('Query failed:', err);
  } else {
    console.log(`${rowCount} row(s) returned`);
  }
});

request.addParameter('Id', TYPES.Int, 1);

request.on('row', (columns) => {
  columns.forEach((column) => {
    console.log(`${column.metadata.colName}: ${column.value}`);
  });
});

connection.execSql(request);
  1. Executing a stored procedure:
const request = new Request('GetUserById', (err, rowCount) => {
  if (err) {
    console.error('Stored procedure failed:', err);
  } else {
    console.log(`${rowCount} row(s) returned`);
  }
});

request.addParameter('Id', TYPES.Int, 1);

request.on('row', (columns) => {
  columns.forEach((column) => {
    console.log(`${column.metadata.colName}: ${column.value}`);
  });
});

connection.callProcedure(request);

Getting Started

  1. Install Tedious:

    npm install tedious
    
  2. Create a connection configuration:

    const config = {
      server: 'your_server.database.windows.net',
      authentication: {
        type: 'default',
        options: {
          userName: 'your_username',
          password: 'your_password'
        }
      },
      options: {
        database: 'your_database',
        encrypt: true
      }
    };
    
  3. Establish a connection and execute a query:

    const { Connection, Request } = require('tedious');
    
    const connection = new Connection(config);
    
    connection.on('connect', (err) => {
      if (err) {
        console.error('Connection failed:', err);
      } else {
        executeQuery();
      }
    });
    
    function executeQuery() {
      const request = new Request("SELECT TOP 10 * FROM YourTable", (err, rowCount) => {
        if (err) {
          console.error('Query failed:', err);
        } else {
          console.log(`${rowCount} row(s) returned`);
          connection.close();
        }
      });
    
      request.on('row', (columns) => {
        columns.forEach((column) => {
          console.log(`${column.metadata.colName}: ${column.value}`);
    

Competitor Comparisons

:zap: fast mysqljs/mysql compatible mysql driver for node.js

Pros of node-mysql2

  • Supports both callback and Promise-based interfaces, offering more flexibility
  • Generally faster performance, especially for large result sets
  • Native support for prepared statements, improving query efficiency and security

Cons of node-mysql2

  • Limited to MySQL databases, while Tedious supports Microsoft SQL Server
  • Less comprehensive documentation compared to Tedious
  • Smaller community and fewer contributors, potentially slower issue resolution

Code Comparison

node-mysql2:

const mysql = require('mysql2/promise');
const connection = await mysql.createConnection({
  host: 'localhost',
  user: 'user',
  database: 'test'
});
const [rows, fields] = await connection.execute('SELECT * FROM users');

Tedious:

const { Connection } = require('tedious');
const config = { server: 'localhost', authentication: { ... } };
const connection = new Connection(config);
connection.on('connect', (err) => {
  connection.execSql('SELECT * FROM users');
});

Both libraries offer similar functionality for connecting to databases and executing queries. node-mysql2 provides a more modern, Promise-based API, while Tedious uses a more traditional callback-based approach. The choice between them often depends on the specific database system being used (MySQL vs SQL Server) and the preferred coding style.

18,264

A pure node.js JavaScript Client implementing the MySQL protocol.

Pros of mysql

  • More mature and widely adopted in the Node.js ecosystem
  • Supports both callback and promise-based APIs
  • Extensive documentation and community support

Cons of mysql

  • Lacks native support for prepared statements
  • Performance can be slower for large result sets
  • Less robust connection pooling compared to tedious

Code Comparison

mysql:

const mysql = require('mysql');
const connection = mysql.createConnection({
  host: 'localhost',
  user: 'user',
  password: 'password',
  database: 'mydb'
});
connection.query('SELECT * FROM users', (error, results) => {
  if (error) throw error;
  console.log(results);
});

tedious:

const { Connection, Request } = require('tedious');
const config = {
  server: 'localhost',
  authentication: { type: 'default', options: { userName: 'user', password: 'password' } },
  options: { database: 'mydb' }
};
const connection = new Connection(config);
connection.on('connect', (err) => {
  if (err) throw err;
  const request = new Request('SELECT * FROM users', (err, rowCount) => {
    if (err) throw err;
    console.log(`${rowCount} rows returned`);
  });
  connection.execSql(request);
});

Both libraries provide Node.js drivers for their respective databases, with mysql focusing on MySQL and MariaDB, while tedious is specifically for Microsoft SQL Server. The choice between them often depends on the database system being used and specific project requirements.

PostgreSQL client for node.js.

Pros of node-postgres

  • More extensive documentation and examples
  • Better support for PostgreSQL-specific features
  • Larger community and more frequent updates

Cons of node-postgres

  • Limited to PostgreSQL databases only
  • Slightly steeper learning curve for beginners

Code Comparison

node-postgres:

const { Pool } = require('pg');
const pool = new Pool();
const result = await pool.query('SELECT * FROM users WHERE id = $1', [userId]);

Tedious:

const Connection = require('tedious').Connection;
const Request = require('tedious').Request;
const connection = new Connection(config);
const request = new Request("SELECT * FROM users WHERE id = @userId", (err, rowCount) => {
  // Handle the result
});
request.addParameter('userId', TYPES.Int, userId);
connection.execSql(request);

Key Differences

  • node-postgres is specifically designed for PostgreSQL, while Tedious is for SQL Server
  • node-postgres uses a more straightforward API with promises and async/await support
  • Tedious requires more setup code and uses a callback-based approach

Use Cases

  • Choose node-postgres for PostgreSQL-specific projects with complex queries
  • Opt for Tedious when working with SQL Server or in Microsoft-centric environments

Both libraries are well-maintained and suitable for production use, with the choice depending on the specific database and project requirements.

19,158

A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.

Pros of Knex

  • Higher-level abstraction, providing a query builder and migrations
  • Database agnostic, supporting multiple SQL databases
  • More user-friendly API for complex queries and joins

Cons of Knex

  • Additional abstraction layer may impact performance for simple queries
  • Learning curve for its specific API and conventions
  • Less fine-grained control over low-level database operations

Code Comparison

Tedious (raw SQL):

const request = new Request(
  'SELECT * FROM users WHERE id = @id',
  (err, rowCount) => {
    if (err) {
      console.error(err);
    } else {
      console.log(`${rowCount} row(s) returned`);
    }
  }
);
request.addParameter('id', TYPES.Int, 1);
connection.execSql(request);

Knex (query builder):

knex('users')
  .where({ id: 1 })
  .select('*')
  .then(rows => {
    console.log(`${rows.length} row(s) returned`);
  })
  .catch(err => {
    console.error(err);
  });

Tedious is a low-level driver for Microsoft SQL Server, offering direct control over database operations. Knex, on the other hand, is a SQL query builder that supports multiple databases, including SQL Server. Knex provides a more abstract and user-friendly API, making it easier to write complex queries and manage database schema changes. However, this abstraction may come at the cost of some performance overhead for simple queries. Tedious allows for more fine-grained control but requires more verbose code for complex operations.

29,432

Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i.

Pros of Sequelize

  • Higher-level ORM with support for multiple databases, not just SQL Server
  • Provides a more intuitive API for database operations and model definitions
  • Includes built-in migration and seeding tools for easier database management

Cons of Sequelize

  • May have a steeper learning curve for developers new to ORMs
  • Can be slower for complex queries compared to raw SQL or lower-level drivers
  • Abstracts away some database-specific features, potentially limiting fine-grained control

Code Comparison

Tedious (low-level connection):

const connection = new Connection(config);
connection.on('connect', (err) => {
  if (err) console.error(err);
  else executeStatement();
});

Sequelize (ORM approach):

const sequelize = new Sequelize('database', 'username', 'password', {
  host: 'localhost',
  dialect: 'mssql'
});
const User = sequelize.define('User', { /* attributes */ });

Tedious is a low-level driver for SQL Server, offering direct control over connections and queries. Sequelize, on the other hand, is a full-featured ORM supporting multiple databases, providing a higher level of abstraction for database operations. While Tedious may offer better performance for specific SQL Server operations, Sequelize provides a more user-friendly API and additional features like migrations and model definitions, making it suitable for a wider range of applications and databases.

34,121

ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

Pros of TypeORM

  • Supports multiple databases (MySQL, PostgreSQL, SQLite, etc.), while Tedious is specific to Microsoft SQL Server
  • Provides an ORM (Object-Relational Mapping) layer, making it easier to work with databases using object-oriented programming
  • Offers advanced features like migrations, relations, and query builders

Cons of TypeORM

  • Steeper learning curve due to its more complex architecture and features
  • May introduce performance overhead compared to Tedious' more direct approach
  • Requires more setup and configuration for basic database operations

Code Comparison

TypeORM example:

@Entity()
class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;
}

Tedious example:

const connection = new Connection(config);
connection.on('connect', (err) => {
  const request = new Request("INSERT INTO Users (Name) VALUES (@Name)", (err) => {
    // Handle error or success
  });
});

TypeORM provides a more declarative and object-oriented approach, while Tedious offers a lower-level, SQL-focused interface. TypeORM is more suitable for complex applications with multiple database support, while Tedious is ideal for Microsoft SQL Server-specific projects requiring fine-grained control over queries and performance.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Tedious (node implementation of TDS)

Dependency Status NPM version Build Status Build Status Slack StatusCode Coverage

Tedious is a pure-Javascript implementation of the TDS protocol, which is used to interact with instances of Microsoft's SQL Server. It is intended to be a fairly slim implementation of the protocol, with not too much additional functionality.

NOTE: New columns are nullable by default as of version 1.11.0

Previous behavior can be restored using config.options.enableAnsiNullDefault = false. See pull request 230.

NOTE: Default login behavior has changed slightly as of version 1.2

See the changelog for version history.

Supported TDS versions

  • TDS 7.4 (SQL Server 2012/2014/2016/2017/2019/2022)
  • TDS 7.3.B (SQL Server 2008 R2)
  • TDS 7.3.A (SQL Server 2008)
  • TDS 7.2 (SQL Server 2005)
  • TDS 7.1 (SQL Server 2000)

Installation

Node.js is a prerequisite for installing tedious. Once you have installed Node.js, installing tedious is simple:

npm install tedious

Getting Started

Documentation

More documentation and code samples are available at tediousjs.github.io/tedious/

Name

Tedious is simply derived from a fast, slightly garbled, pronunciation of the letters T, D and S.

Developer Survey

We'd like to learn more about how you use tedious:

Contributing

We welcome contributions from the community. Feel free to checkout the code and submit pull requests.

License

Copyright (c) 2010-2021 Mike D Pilsbury

The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

NPM DownloadsLast 30 Days