azstore 0.0.2 copy "azstore: ^0.0.2" to clipboard
azstore: ^0.0.2 copied to clipboard

outdated

Access azure storage options via REST APIs.

azstore #

Access azure storage options via REST APIs.

Getting Started #

This package handles all the encryption and formatting required to provide easy access to azure storage options via REST APIs. The package currently provides functions to query and upload data to Azure blobs, tables and queues. Add the latest dependency to your pubspec.yaml to get started. azstore: ^latest_version and import. In the following examples, 'your connection string' can be gotten from the azure portal.

Azure Blob Functions. #

Upload file to blob with putBlob function. body and bodyBytes are exclusive and mandatory.

Example:

Future<void> testUploadImage() async {
  File testFile =File('C:/Users/HP/Pictures/fdblack.png');
  Uint8List bytes = testFile.readAsBytesSync();
  var storage = AzureStorage.parse('your connection string');
  try {
    await storage.putBlob('/azpics/fdblack.png',
      bodyBytes: bytes,
      contentType: 'image/png',
    );
  }catch(e){
    print('exception: $e');
  }
}

Text can also be uploaded to blob in which case body parameter is specified instead of bodyBytes .

Delete blob operations can also be performed as shown.

Future<void> testDeleteBlob() async {
  var storage = AzureStorage.parse('your connection string');
  try {
    await storage.deleteBlob('/azpics/fdblack.png');
    print('done deleting');//Do something else
  }catch(e){
    print('exception: $e');
  }
}

Also explore the appendBlock function.

Table Storage Functions #

The Azure Table service offers structured NoSQL storage in the form of tables. Tables can be managed using the createTable,deleteTable and getTables functions. Table nodes/rows can be controlled using other functions such as upsertTableRow,putTableRow,getTableRow and deleteTableRow.

The following snippets show the use of some table access functions. Also refer to the Azure Tables docs for allowed data types to insert in a table row. The code documentation provides further help.

Use upsertTableRow when updating or adding new table row and putTableRow to replace or add a new row.

Future<void> testUpload2Table() async {
  var storage = AzureStorage.parse('your connection string');
  try {
    var myPartitionKey='partition_key';
    var myRowKey='237';
    Map<String, dynamic> rowMap={"Address":"Santa Clara",
    "Age":23,
    "AmountDue":200.23,
    "CustomerCode@odata.type":"Edm.Guid",
    "CustomerCode":"c9da6455-213d-42c9-9a79-3e9149a57833",
    "CustomerSince@odata.type":"Edm.DateTime",
     "CustomerSince":"2008-07-10T00:00:00",
     "IsActive":false,
     "NumberOfOrders@odata.type":"Edm.Int64",
     "NumberOfOrders":"255",
     "PartitionKey":"$myPartitionKey",
     "RowKey":"$myRowKey"
    };
    await storage.upsertTableRow(
        tableName: 'profiles',
        rowKey:myRowKey,
        bodyMap: rowMap
     );
  }catch(e){
    print('tables upsert exception: $e');
  }
}

Specific Table rows can be retrieved using getTableRow function as shown below. Filters can also be used to retrieve a list of table rows by using the filterTableRows function specifying the filter logic in the filter parameter.

Future<void> testGetTableRow() async {
  var storage = AzureStorage.parse('your connection string');
  try {
    var myPartitionKey='partition_key';
    var myRowKey='unique_row_id';
    String result=await storage.getTableRow(
        tableName: 'profiles',
        partitionKey:myPartitionKey,
        rowKey:myRowKey,
        fields: ['Address','CustomerSince']
    );
    print('result: $result');
  }catch(e){
    print('tables get exception: $e');
  }
}

Future<void> testFilterTable() async {
  var storage = AzureStorage.parse('your connection string');
  List<String> result=await storage.filterTableRows(tableName: 'profiles',
   filter: 'Age%20lt%2024',
   fields: ['Age','CustomerSince'],
   top:30
   );
  print('\nFilter results');
  for(String res in result){
    print(res);
  }
}

Table rows can also be deleted.

Future<void> testDeleteTableRow() async {
  try {
    var storage = AzureStorage.parse('your connection string');
    await storage.deleteTableRow(tableName: 'profiles', partitionKey: 'fgtdssdas', rowKey: '232');
  }catch(e){
    print('delete exception: $e');
  }
}

Azure Queue Functions #

Azure Queue Storage allows you store large numbers of messages. Queues in your storage account can easily be managed using createQueue, deleteQueue, getQList and getQData functions.

Future<void> testCreateQ() async {
  try{
      var storage = AzureStorage.parse('your connection string');
      await storage.createQueue('myqueue');
  }catch(e){
     print('create queue error: $e');
  }
}

Future<void> testGetQData() async {
  var storage = AzureStorage.parse('your connection string');
  try {
    String qName='myqueue';
    Map<String, String> result = await storage.getQData(qName);
    print('showing $qName data:\n');
    for (var res in result.entries) {
      print('${res.key}: ${res.value}');
    }
  }catch(e){
    print('get queue data error: $e');
  }
}

Future<void> testGetQList() async {
  try{
  var storage = AzureStorage.parse('your connection string');
  List<String> result=await storage.getQList();

  print('showing queue list\n');
  for(String res in result){
    print(res);
  }
  }catch(e){
     print('get queue list error: $e');
  }
}

Future<void> testDeleteQ() async {
  try{
      var storage = AzureStorage.parse('your connection string');
      await storage.deleteQueue('myqueue');
  }catch(e){
    print('delete queue error: $e');
  }
}

To insert and access messages in a queue, the functions putQMessage, getQmessages,peekQmessages,clearQmessages and delQmessages can be used as shown below.


Future<void> testPutMessage() async {
  var storage = AzureStorage.parse('your connection string');
  try {
     await storage.putQMessage(qName:'ttable', message: 'testing queue updates');
  }catch(e){
    print('get data error: ${e.statusCode} ${e.message}');
  }
}

Future<void> testGetQMessages() async {
  var storage = AzureStorage.parse('your connection string');
  print('working on results...');
  try {
    List<AzureQMessage> result = await storage.getQmessages(qName: 'ttable',
      numOfmessages: 10
    );
    print('showing get results');
    for (var res in result) {
      print('message ${res}');
    }
  }catch (e){
    print('Q get messages exception $e');
  }
}

Future<void> testPeekQMessages() async {
  var storage = AzureStorage.parse('your connection string');
  try {
    List<AzureQMessage> result = await storage.peekQmessages(qName: 'ttable');
    print('showing peek results');
    for (var res in result) {
      print('message ${res.messageText}');
    }
  }catch (e){
    print('Q peek messages exception $e');
  }
}

Future<void> testClearQMessage() async {
  var storage = AzureStorage.parse('your connection string');
  try {
    await storage.clearQmessages('ttable');
  }catch(e){
    print('clear QM error: ${e.statusCode} ${e.message}');
  }
}

Future<void> testDeleteMessage() async {
  var storage = AzureStorage.parse('your connection string');
  try {
    await storage.delQmessages(qName: 'ttable',
     messageId: '27bc633b-4de0-42bf-bea6-0860bd410f4e',
      popReceipt: 'AgAAAAMAAAAAAAAAX3e0UwAg1wE='
      );
  }catch(e){
    print('delete QM error: $e');
  }
}

The package provides internal documentation and required function parameters to ease working with functions. Also refer to the Azure official documentation for details on queue operations and messages lifecycle.

8
likes
0
pub points
84%
popularity

Publisher

verified publisheralgure.tech

Access azure storage options via REST APIs.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

crypto, flutter, http, xml

More

Packages that depend on azstore