Skip to content

Instantly share code, notes, and snippets.

View naveen1337's full-sized avatar

Naveen 1337 naveen1337

View GitHub Profile
@naveen1337
naveen1337 / demo.ts
Created December 23, 2024 15:14 — forked from vedantroy/demo.ts
SQLite-backed key-value store with JS-like object manipulation and automatic JSON serialization.
import Database from 'better-sqlite3';
import { createDatabaseClient } from './proxy.ts';
// 1) Create an in-memory DB and your table(s).
const db = new Database(':memory:');
db.exec(`
CREATE TABLE users (
id TEXT PRIMARY KEY,
data JSON
);
@naveen1337
naveen1337 / migrate.js
Created December 8, 2024 16:32
sql reference table for the constants
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return Promise.all([
refConstants(knex),
VendorsTransactionTable(knex)
]);
}
from configs.db_connection import release_conn
from pydantic import BaseModel
from psycopg2 import sql, extras
import logging
from constants.function_debug_codes import db_query_codes
from constants.app_constants import __ENV__
import traceback
async def get_rows(
@naveen1337
naveen1337 / uniqueConstraintCheck.ts
Created December 24, 2023 12:49
unique column check with knex in nodejs
export async function uniqueConstraintCheck(
connection: typeof dbConnection,
{
tbl,
select,
whereCol,
whereValue,
input
}: any) {
const eCode = genQueryCodes["uniqueConstraintCheck"]
@naveen1337
naveen1337 / update_records.py
Last active November 5, 2023 14:11
update_many_records_using_pyscopg
async def update_many_columns(
cursor, tbl, new_data, where_col, where_value,limit=None, returning=None
):
debug_code = db_query_codes["update_many_columns"]
try:
query = sql.SQL("UPDATE {tbl} SET {new_data} WHERE {where_col} = {where_value}").format(
tbl=sql.Identifier(tbl),
where_col=sql.Identifier(where_col),
where_value=sql.Literal(where_value),
const exportReq = useMutation(exportDataRemote, {
onSuccess: (data) => {
var file = window.URL.createObjectURL(data);
var a = document.createElement('a');
a.href = file;
a.download = "donations.csv";
document.body.appendChild(a);
a.click();
a.remove();
console.log(file);
@naveen1337
naveen1337 / sql_script.py
Created April 1, 2023 09:10
sql_script.py
import json
import psycopg2
# Load JSON data from file
with open('data.json') as f:
data = json.load(f)
# Establish a database connection
conn = psycopg2.connect(dbname='test_db', user='postgres', password='password', host='127.0.0.1')
cur = conn.cursor()
@naveen1337
naveen1337 / download_blob.ts
Created March 29, 2023 08:42
download_blob.ts
const distibutionReq = useMutation(exportDataRemote, {
onSuccess: (data) => {
var file = window.URL.createObjectURL(data);
var a = document.createElement('a');
a.href = file;
a.download = "distribution.csv";
document.body.appendChild(a);
a.click();
a.remove();
console.log(file);
@naveen1337
naveen1337 / psycopg_update_column.py
Last active March 25, 2023 18:13
psycopg_update_column.py
async def update_many_columns(
cursor, tbl, new_data, where_col, where_value,limit=None, returning=None
):
try:
query = sql.SQL("UPDATE {tbl} SET {new_data} WHERE {where_col} = {where_value}").format(
tbl=sql.Identifier(tbl),
where_col=sql.Identifier(where_col),
where_value=sql.Literal(where_value),
new_data=sql.SQL(", ").join(
sql.Composed(
@naveen1337
naveen1337 / react_native_check_isScreenReady_custom_hook.ts
Created March 3, 2023 13:13
react_native_check_isScreenReady_custom_hook
export function useIsScreenReady() {
const [screenReady, setScreenReady] = useState(false);
useEffect(() => {
InteractionManager.runAfterInteractions(() => {
setScreenReady(true);
});
}, []);
return screenReady;
}