database

php
<?php

use Illuminate\Support\Facades\DB;

public function createOrder(array $items, User $user)
{

Laravel database transactions for data integrity

laravel database transactions
by Carlos Mendez 3 tabs
php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Generating URL Slugs from Titles with a Laravel Model Observer

laravel eloquent observers
by codesnips 4 tabs
go
package feed

import (
	"encoding/base64"
	"encoding/json"
	"time"

Cursor-Based Keyset Pagination for a Postgres Feed API in Go

go postgres pagination
by codesnips 3 tabs
python
from django.db import models
from django.contrib.postgres.indexes import GinIndex


class Post(models.Model):
    title = models.CharField(max_length=200, db_index=True)

Django database index strategies

django python database
by Priya Sharma 1 tab
rust
use std::fs;
use std::path::Path;

#[derive(Debug, Clone)]
pub struct Migration {
    pub version: i64,

Sequential Schema Migrations With Version Tracking in Rust and Postgres

migrations postgres sql
by codesnips 3 tabs
javascript
function escapeCell(value) {
  if (value === null || value === undefined) return '';
  const str = String(value);
  if (/[",\n\r]/.test(str)) {
    return '"' + str.replace(/"/g, '""') + '"';
  }

Stream a Large CSV Export in Express with Backpressure and an Async Row Generator

express streaming csv
by codesnips 3 tabs
python
from alembic import op
import sqlalchemy as sa

revision = "20240612_add_status"
down_revision = "20240515_create_orders"
branch_labels = None

Zero-Downtime NOT NULL Column Backfill with Alembic and SQLAlchemy

alembic sqlalchemy migrations
by codesnips 2 tabs
python
from django.db import models


class Product(models.Model):
    name = models.CharField(max_length=200)
    sku = models.CharField(max_length=50)

Django model meta options for database optimization

django python models
by Priya Sharma 1 tab
python
from django.db import models
from django.contrib.postgres.indexes import GinIndex, BTreeIndex


class Order(models.Model):
    customer = models.ForeignKey('Customer', on_delete=models.CASCADE)

Django database indexes for query performance

django python database
by Priya Sharma 1 tab
python
import hashlib
from datetime import datetime, timezone

from sqlalchemy import BigInteger, Column, DateTime, String, UniqueConstraint
from sqlalchemy.orm import declarative_base

Efficient Bulk Insert in SQLAlchemy with a Reusable Chunking Helper

sqlalchemy postgres bulk-insert
by codesnips 3 tabs
php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Slugify Post Titles on Save With a Laravel Model Observer and Guaranteed Uniqueness

laravel eloquent observer
by codesnips 4 tabs
go
package bank

import "errors"

var ErrVersionConflict = errors.New("optimistic lock: version conflict")
var ErrInsufficientFunds = errors.New("insufficient funds")

Optimistic Locking in Go With a Version Column on UPDATE

optimistic-locking concurrency postgres
by codesnips 3 tabs