1.1.8 • Published 3 years ago

react-native-azure-cosmos-epg v1.1.8

Weekly downloads
1
License
ISC
Repository
github
Last release
3 years ago

react-native-azure-cosmos-epg

This package provide query and insert against azure cosmos db

Install

npm i react-native-azure-cosmos-epg --save

Usage

Import library

import { azurefetch, initAzureCosmos } from 'react-native-azure-cosmos-epg/azurecosmos'

Init Cosmos Authentication

Using Master Key

class App extends React.Component {
  constructor(props) {
    super(props);
    initAzureCosmos(
    {
      masterKey:${YOUR COSMOS DB MASTER KEY},
      version: "2018-12-31",
      dbUri: ${YOUR COSMOS DB URL},
      dbname: ${YOUR COSMOS DB NAME},

    }
    ...
  }

Using Resource Tokens

class App extends React.Component {
  constructor(props) {
    super(props);
    initAzureCosmos(
    {
      masterKey:'',
      version: "2018-12-31",
      dbUri: ${YOUR COSMOS DB URL},
      dbname: ${YOUR COSMOS DB NAME},
      resourcesTokens: ${USER RESOURCE TOKENS FROM BROKER SERVICE}
    }
    ...
  }

Broker should append the collection (container) name to the resource token ID, example for a collection called 'Countries':

 ...
 "id": "SOMEIDHERE_Countries",
 ...

Notice the underscore.

Run a Query

azure = async () => {
   const response = await azurefetch({
            dbname : "", //optional parameter if you want to quiry agiants another DB
            col: ${COL NAME},
            body: {
                "query": "SELECT c.id FROM ${COL NAME} c WHERE c.uid = @email",
                "parameters": [
                    { "name": "@email", "value": email }
                ]
            },
            type: 'Query',
            partitionKey: ${PARTITION VALUE}
        });

  }

Insert New Documents

azure = async () => {
    const response = await azurefetch({
              col: ${COL NAME},
              body: {
                  "id": username,
                  "code": code,
                  "name": name,
                  "photoUri": photoURL,
              },
              type: 'Insert',
              partitionKey:  ${PARTITION VALUE}
          });

Execute Stored Procedure

azure = async () => {
   const response = await azurefetch({
        spname: ${SP NAME},
        col: ${COL NAME},
        body: [id, { "photoUri": photoURL }],
        type: 'Sp',
        partitionKey: code
    });
1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago