Skip to content

Instantly share code, notes, and snippets.

View mansha99's full-sized avatar

Manish Sharma mansha99

View GitHub Profile
@mansha99
mansha99 / models.py
Created September 5, 2023 11:04
using DeclarativeBase to define Models of ORM in SQLAlchemy
from sqlalchemy import String
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy import Integer,String,Float
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
class Base(DeclarativeBase):
pass
class Planet(Base):
__tablename__ = "planet"
@mansha99
mansha99 / db.py
Last active September 5, 2023 10:59
Initializing SQLAchemy Session
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
import pymysql
pymysql.install_as_MySQLdb() #MySQL specific
connectionString="mysql+mysqldb://root:India12#$@localhost/alchemydb2"
engine = create_engine(connectionString,echo=False)#echo True will print on screen
session = Session(engine)
@mansha99
mansha99 / VerificationController.php
Created August 21, 2023 06:42
Factory Pattern Laravel Client controller
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\MobileVerificationRequest;
use App\Services\SmsService;
class VerificationController extends Controller
{
<?php
namespace App\Listeners;
use App\Events\AddressChangeEvent;
use Illuminate\Support\Facades\Log;
class AddressChangeListenerForLogistics
{
public function __construct()
<?php
namespace App\Events;
use App\Models\Order;
use Illuminate\Foundation\Events\Dispatchable;
class AddressChangeEvent
{
use Dispatchable;
<?php
namespace App\Services;
use App\Events\AddressChangeEvent;
use App\Models\Order;
class AddressChangeNotifService
{
<?php
namespace App\Services;
use App\DTO\AddressChangeDTO;
use App\Models\Order;
use App\Respository\OrderRepository;
use Exception;
class OrderService
@mansha99
mansha99 / AddressController.php
Created August 19, 2023 10:51
Observer Pattern Laravel Controller
<?php
namespace App\Http\Controllers;
use App\DTO\AddressChangeDTO;
use App\Http\Requests\AddressChangeRequest;
use App\Services\OrderService;
class AddressController extends Controller
{
@mansha99
mansha99 / models.py
Created August 18, 2023 16:34
Model Tracking in Django
from django.db import models
from model_utils import FieldTracker
from stock import signals
class Stock(models.Model):
code = models.CharField(max_length=20,unique=True)
name = models.CharField(max_length=120)
current_value = models.FloatField()
#
current_value_tracker = FieldTracker(fields=['current_value'])
#
@mansha99
mansha99 / employee.json
Created August 13, 2023 09:22
Populating Solr collection
[
{
"id": "emp-001",
"name": "Chris Nathan",
"department": "Dev",
"designation": "Analyst",
"experience": 7
},
{
"id": "emp-002",