Giter VIP home page Giter VIP logo

sqlcdcstream's Introduction

sqlcdcstream

Is a node.js module that enables changes made to data an Microsoft SQL Server Database Table to be converted to a stream.

It captures all CRUD operations on a table and utilises the built in Change Data Capture functionality of SQL Server.

Install

npm install sqlcdcstream

If your database server does not currently have sqlcdcstream schema do either of the following

> node node-modules\sqlcdcstream\install-database.js

Or run the script sql\installsqlcdc.sql on the database server

> osql -E -n-1 -i .\sql\installsqlcdc.sql -o install-database.log

This creates a database on the local instance to store the id of the latest record. You will find the output of these commands in install-database.log The script will not delete the database if it already exists.

Configuration

Enable SQL Server Change Data Capture on the Database

> osql -E 
1> USE NAME_OF_YOUR_DATABASE
2> GO
1> EXEC sys.sp_cdc_enable_db
2> GO

Enable Change Data Capture on a Table

> osql -E 
1> USE NAME_OF_YOUR_DATABASE
2> GO
1> EXECUTE sys.sp_cdc_enable_table 
	@source_schema = N'SCHEMA NAME E.G. dbo', 
	@source_name = N'TABLE_NAME', 
	@capture_instance = N'SCHEMA_NAME_TABLE_NAME'";
2> GO

Usage

Write a program to emit changes

var mystream = require('sqlcdc')
var connection =  "Driver={SQL Server Native Client 11.0};Server=(local);Database=DB_NAME;Trusted_Connection={Yes}"
var schema = "dbo"
var tablename = "NAME_OF_TABLE"
var interval = 1000 //frequency the table is polled
var stm = mystream.changes(connection, schema, tablename, interval);
stm.pipe(process.stdout);

sqlcdcstream's People

Contributors

no9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.