react-native-mssql

0.1.4 • Public • Published

react-native-mssql

MSSQL Native Plugin for React Native for Android

This is a basic implementation of MSSQL on Android allowing opening, closing and running sql on remote databases. This plugin does not allow an MSSQL database to be packaged locally on Android devices. The plugin only communication between remote databases.

Please let me know your projects that use these MSSQL React Native modules. I will list them in the reference section. If there are any features that you think would benefit this library please post them.

Step 1 - NPM Install

npm install --save react-native-mssql

Step 2 - Linking dependencies

react-native link react-native-mssql

Using The Plugin

import MSSQL from 'react-native-mssql';
...

Connect a Database

    const config = {
        server: '192.168.1.1', //ip address of the mssql database
        username: 'sa', //username to login to the database
        password: 'password', //password to login to the database
        database: 'admin', //the name of the database to connect to
        port: 1234, //OPTIONAL, port of the database on the server
        timeout: 5, //OPTIONAL, login timeout for the server
    }
    const connected = await MSSQL.connect(config);

Returns a promise indicating if the connection was successful.

Execute SQL

    const query = 'SELECT TOP * FROM USERS'
    const result = await MSSQL.executeQuery(query);

Returns a promise with the query results. If Getting data from a table the promise will return an array of objects for each table row.

Execute Update SQL

    const query = 'UPDATE USERS SET Active=0'
    const result = await MSSQL.executeUpdate(query);

Returns a promise with the number of rows updated. Use this method if performing INSERT, UPDATE or DELETE statements on a database.

Close a Database

    const closed = await MSSQL.close();

Closes the currently open database (if any) and returns a promise indicating if the close was successful. It is not necessary to open and close the database when required unless working with multiple databases.

Package Sidebar

Install

npm i react-native-mssql

Weekly Downloads

26

Version

0.1.4

License

MIT

Unpacked Size

344 kB

Total Files

14

Last publish

Collaborators

  • davidstoneham