Posts

Build a Python Flask CRUD App with Azure File Storage

Image
This guide walks you through building a CRUD application using Python Flask and Azure File Storage from scratch. You'll learn how to connect Flask with Azure Blob Storage, handle file uploads, list files, and delete files seamlessly. 1. Prerequisites Python installed (Python 3.7+ recommended). An Azure account . Azure Storage Account created. Create one here if needed. Install the required Python packages: pip install flask azure- storage - file - share python-dotenv 2. Setting up Azure File Storage Create a Storage Account : Go to the Azure portal and create a Storage Account . Note down the Storage Account Name and Access Key . Create a File Share : Inside your Storage Account, navigate to File Shares . Create a new file share and note its Name . 3. Project Structure Create the following directory structure for your project: flask-azure-file- storage / ├── app.py ├── .env ├── requirements.txt └── templates/ ├── index .html ├── upload.html └── files.html 4. In...

Comprehensive Guide to Pagination and Sorting in Spring Boot with Spring Data JPA

Image
Pagination and sorting are essential features for developing scalable and performant applications that deal with large datasets. Spring Data JPA provides built-in mechanisms to easily implement these functionalities. 1. Setting Up a Spring Boot Project Dependencies To get started, include the necessary dependencies in your pom.xml if using Maven: <dependencies> <dependency> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-starter-data-jpa </artifactId> </dependency> <dependency> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-starter-web </artifactId> </dependency> <dependency> <groupId> com.h2database </groupId> <artifactId> h2 </artifactId> <scope> runtime </scope> </dependency> </dependencies> 2. Database Configurat...

Custom Result Set Mapping in Spring Data JPA: Native Query to DTO Mapping Guide

Image
In Spring Data JPA, when working with native queries , the default result mapping may not be sufficient if the query returns a result that doesn't map directly to an entity or needs additional customization. For this purpose, you can use Result Set Mapping to create custom mappings for native query results. Below is a step-by-step guide to implement Result Set Mapping in Spring Data JPA from scratch: 1. Use @SqlResultSetMapping for Custom Mapping You can define a custom result set mapping using the @SqlResultSetMapping annotation. This can be used to map query results to either: Entities Scalar values DTOs 2. Define the Entity and DTO Classes Let's assume you have an Employee entity and want to map a custom result (e.g., only name and salary ) into a DTO. Entity Class @Entity @Table (name = "employees" ) public class Employee { @Id @GeneratedValue (strategy = GenerationType.IDENTITY) private Long id; @Column (name = "name" ) priv...

Using Stored Procedures for Bulk Operations in Spring Data JPA

Image
1. Introduction Spring Data JPA provides a way to call stored procedures using the @Procedure annotation or native queries. Stored procedures are useful for bulk operations, as they can significantly improve performance by reducing round trips to the database. In this guide, we will: Create a stored procedure for bulk operations (insert/update/delete). Call the stored procedure using Spring Data JPA in a Spring Boot application. Test the stored procedure execution. 2. Setting Up the Project 2.1 Dependencies Add the following dependencies to your pom.xml : < dependencies > <!-- Spring Boot Starter Data JPA --> < dependency > < groupId > org.springframework.boot </ groupId > < artifactId > spring-boot-starter-data-jpa </ artifactId > </ dependency > <!-- Spring Boot Starter Web --> < dependency > < groupId > org.springframework.boot </ groupId > < ar...