#databases

1 messages · Page 37 of 1

edgy sail
#

hello how do i make my code faster and more pythonic

oblique estuary
#

When I try to connect my python mysql database in idle, It shows RESTART: SHELL without any error. Does anyone know how to solve it?

rare root
#

This is website for Python..

glacial ether
#

what are all the types of apis?

#

ie i can get a api froma movie website to show the movie dates and names

#

what else can i do with apis

fading patrol
fleet ibex
nocturne wren
#

As a beginner how do i get started with databased

#

I've heard about the django framework but idk if its beginner friendly/recommended

slim cypress
#

After that there isn't much I can give

coral wasp
wooden topaz
#

Hi,

CREATE TABLE students (
  id int, 
  Firstname varchar (200), 
  Lastname varchar (200), 
  Email varchar (100)
);

Insert into students 
Values 
  (1, "Watson", "Keter", "Watsonketer@gmail.com");

It says column "Watson" does not exist.

flat pawn
brave bluff
#

Can anyone help direct me on how I filter on a relationship in sqlalchemy 2.0?

tranquil aspen
#

Need more info

median orbit
#

Guys, Do u have info about indexing, query optimization and etc? Mb book/video

brave bluff
#

I figured out the filtering thing; I realized I was thining about the code wrong. SQLA goes a lot more explicit, so doing the join and filtering on the join was my correct route.

#

I'm having trouble with a UUID field. I have this right now:

token: Mapped[UUID] = mapped_column(String(36), default=uuid4)

Problem is when I create a new object and save it to the database, it doesn't convert the UUID to string, and I'm not sure how to fix that. I'd figure as the column is a string type, it'd do the conversion internally?

tranquil aspen
#

str()

brave bluff
#

... where?

#

On every use of the field? Given it's being auto generated, I can't do that

#

I could remove the default, but then what's the point?

thorny anchor
deep heron
#

When pushing data to MariaDB, has anyone found it's better to push something similar to the datatype for a field on the database? Or just push strings and hope for the best?

steep locust
#

hey i need help guys how can i store the info1 and 2 into the columns of abc using panda, im having a really hard time with this

glacial ether
#

for small to medium scale apps what are the languages used for the backend? same as front end ie python or different?

normal sentinel
#

what would be a good way to design a system of workout routines, where each routine has a set of exercises, where each exercise has sets of repetitions but those sets can be different for each routine

#

(in sql)

brave bluff
#

You basically designed it yourself there

#

You add extra info in the join tables between them

#

So a table of routines and a table for exercises. Join table between routines and exercises contains data on how many sets and reps

#

I'm again stuck with SQLA basics. I have a field

activated_on: Mapped[datetime.datetime] = mapped_column(nullable=True)

I'm setting it as

self.activated_on = datetime.datetime.now(datetime.timezone.utc)

Yet I'm getting

gamersplane-api    | sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class 'asyncpg.exceptions.DataError'>: invalid input for query argument $1: datetime.datetime(2024, 12, 15, 23, 7, 4... (can't subtract offset-naive and offset-aware datetimes)
gamersplane-api    | [SQL: UPDATE users SET activated_on=$1::TIMESTAMP WITHOUT TIME ZONE WHERE users.id = $2::INTEGER]
gamersplane-api    | [parameters: (datetime.datetime(2024, 12, 15, 23, 7, 42, 438459, tzinfo=datetime.timezone.utc), 1)]
gamersplane-api    | (Background on this error at: https://sqlalche.me/e/20/dbapi)

as my error? I'm not doing any datetime subtraction here. It looks like the SQL is trying to do tz independent timestamp, whereas I'm using a tz to set mine. Do I need to manually coerse that data? If so, that's stupid as hell.

coral wasp
normal sentinel
#

idk just have the user enter their stuff

coral wasp
#

Or are you just storing the workout history, like logging their weight/sets/reps?

normal sentinel
#

not doing anything too fancy but just a logger

coral wasp
#

Have just an exercise table: date, exercise, set #, weight, num_reps

normal sentinel
#

but in routines

#

i want exercises to have different sets and number of reps per routine

coral wasp
#

Ok, routine name, exercise, set number, weight, reps

normal sentinel
#

thats probably what i should do but

#

it feels like i could do more with sql

coral wasp
#

You could have a separate table for each exercise with information about it, like instructions or target muscles

normal sentinel
#

yeah thats it thx

coral wasp
normal sentinel
#

yeah

normal sentinel
#

alr so i came up with this

#

in a program, should i keep opening and closing new connections and cursors, just the cursor, or having both of them open when the program starts and closingm when it ends?

paper flower
#

Having an open connection is fine (if it's sqlite)

paper flower
normal sentinel
#

yeah i just thought about that

#

but how do i do that relation between the exercises column of routines and the exercises

#

is there something specific i have to do in the table creation?

paper flower
#

Not really, but you in most (99% of) cases create a foreign key

#

in your case excercises table would have a foreign key to routines.id

normal sentinel
#

what is a foreign key though

paper flower
#

That's something that you could look up by yourself, I don't think I'm that good at explaining stuff 😉 but tldr it helps to keep database consistent, e.g. if you use an excercise_id that doesn't exist it would throw an error

normal sentinel
#

ok

#

well thx

normal sentinel
paper flower
#

Maybe like this?

CREATE TABLE IF NOT EXISTS exercises (
  id INTEGER PRIMARY KEY, -- Change routine_id to just id, also should have been "excercise_id" if you want to follow that naming scheme
  name TEXT,
  date_modified INTEGER,
  note TEXT
);
CREATE TABLE IF NOT EXISTS routines (
    id INTEGER PRIMARY KEY,  -- Can be just id
    excercise_id INTEGER NOT NULL,
    name TEXT,
    date_modified INTEGER,
    note TEXT,
    FOREIGN KEY (excercise_id)  -- We reference `excercises.id` by `excercise_id` column
        REFERENCES exercises (id)
);
#

Also would be a good idea to sprinkle not null everywhere, columns in sql are nullable by default

normal sentinel
#

ok

paper flower
#

Regarding naming - there's no need to name columns/fields as entity_id when you already know they belong to entity

#

e.g.

class User:
    id: int

would be better than

class User:
    user_id: int
normal sentinel
#

oh wait

#

whats the exercise_id in routines for

paper flower
#

to reference the excercise?

#

if you use your primary key for that then you'd only be able to have one excercise per routine, since primary keys are unique

normal sentinel
#

so i may have forgotten that each exercise needs to have a number of sets and repetitions

#

but they should be custom to each routine

stable tree
#

Hey everyone! Would setting up my own home server out of an old pc be a good learning experience as an aspiring backend dev? Or would it be better to allocate my time elsewhere?

coral wasp
# normal sentinel alr so i came up with this

In a routine, each exercise may have multiple sets. And each set may have different reps and weights. For instance, I'll do warmup sets of squats at 10 reps, and then my working sets are 5 reps. Sometimes I'll do a drop set where a single set has multiple weights

#

Broadly: the question is whether you're building a logger or a planner. You originally said a workout logger, but your schema looks more like a planner.

#

(Or perhaps a planner + logger)

wise goblet
#

psql/pg_dump(and psycopg2 if using not binary) versions
fall apart for us with error

/usr/lib/postgresql/16/bin/pg_dump: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory

if installing postgres-client-16 in python:3.11-bullseye docker image.

FROM public.ecr.aws/docker/library/python:3.11-bullseye AS builder
# Setup working directory
RUN mkdir /code
WORKDIR /code

RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ bullseye-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN curl -s https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN apt-get update \
    && apt-get install -y \
    postgresql-client-16 \
    && rm -r /var/lib/apt/lists/*

They have the same libpq appears randomly on psycopg import or pg_dump activation. perhaps someone has ideas how to resolve it or how to google some place which has information about it
error is reproducable if just trying pg_dump -h db -U postgres to dump default postgres within this docker image

May be there is an option to install postgres-client-16 to python image in another way 🤔

icy oyster
#

SQLITE_CORRUPT: sqlite3 result code 11: database disk image is malformed
think_cheese first time in my life I see this in the vscode sqlite viewer extension

swift talon
#

Im writing an SQL lexer as a elarning project, does this belong to this category or should I cdiscuss it somewhere else?

brave bluff
#

Anyone know if there's a way to connect to a postgres db host and drop the only database on there with asyncpg? I'm trying to connect as

    conn = await asyncpg.connect(
        host=DATABASE_HOST,
        user=DATABASE_USER,
        password=DATABASE_PASSWORD,
    )

but it keeps saying it can't drop the currently open database.

wise goblet
brave bluff
#

I'm also trying DROP OWNED BY {DATABASE_USER}, but then I get

cannot drop objects owned by role gamersplane because they are required by the database system
#

Hm... this is a docker container running postgres, I'll look into if I have access to an postgres user.

#

Oh, not user, you mean db, got it

#

I'll try that

#

Actually no, this one doesn't

#

bah, will I have to drop the volume... that'll be annoying and a lot slower...

brave bluff
#

Ok, onto a sqlalchemy thing...
Anyone know what's going on here? I'm not sure what I've missed. I have a script to populate my local db with test data. I'm getting as far as

        user = await register_user(
            email="contact@gamersplane.com", username="Keleth", password="test1234"
        )
        user.activate()
        db_session.add(user)
        await db_session.commit()

        admin_role = Role(name="Admin", owner_id=user.id)

At which point it throws an error can't set attribute because of name, which is a @hybrid_property. It's defined as

    _name: Mapped[str] = mapped_column("name", String(64), unique=True)
    _plural: Mapped[str] = mapped_column("plural", String(64), unique=True)

With the methods themselves being

    @hybrid_property
    def name(self):
        return self._name

    @name.setter
    def set_name(self, value):
        self._name = value
        self._plural = pluralize(self._name)

Can anyone spot what I've done wrong?

paper flower
brave bluff
paper flower
#

Uhh, let me try to reproduce it

#

Hm, why are you using hybrid property here?

#

Hm, nvm

#

Rename set_name to name

#

so your function name should match

#

otherwise you'd have two different properties, in your case it looks like this:

name = property(fget=your_getter)
set_name = property(fget=your_getter, fset=your_setter)
#

Btw, are you using MappedAsDataclass or not? It's a bit finnicky to set up with properties, but:

class Book(MappedAsDataclass, Base):
    __tablename__ = "book"

    id: Mapped[int] = mapped_column(primary_key=True, init=False)

    _name: Mapped[str] = mapped_column("name", String(64), unique=True, init=False)
    _plural: Mapped[str] = mapped_column("plural", String(64), unique=True, init=False)
    name: Mapped[str]

    @hybrid_property
    def name(self):
        return self._name

    @name.setter
    def name(self, value):
        self._name = value
        self._plural = value * 2

Same seems to apply with standard dataclasses too (you need to define your annotation/field separately from the property):

@dataclasses.dataclass
class Class:
    _name: str
    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, value: str) -> None:
        self._name = value


Class(name="Name") # TypeError: Class.__init__() got an unexpected keyword argument 'name'
@dataclasses.dataclass
class Class:
    name: str
    _name: str = dataclasses.field(init=False)

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, value: str) -> None:
        self._name = value


c = Class(name="Name")
print(c.__dict__)  # {'_name': 'Name'}
brave bluff
#

That's confusing. The SQLA docs use this as the example:

class Interval(Base):
    # ...

    @hybrid_property
    def length(self) -> int:
        return self.end - self.start

    @length.inplace.setter
    def _length_setter(self, value: int) -> None:
        self.end = self.start + value
#

As always, the SQLA docs suck

#

I'm actually unfamiliar with MappedAsDataclass, but I'll look into it

#

Oh, I need that .inplace. Of course, instead of just saying what to do and why, the SQLA docs do a 3 paragraph explaination of of stuff, with a little bit at the end of how to get it working (with middling clarity)

brave bluff
#

Is this not how I add an item to a many to many with SQLA?

        user.roles.append(admin_role)
        db_session.add(user)
        await db_session.commit()
#

I get sqlalchemy.exc.MissingGreenlet: greenlet_spawn has not been called; can't call await_only() here. Was IO attempted in an unexpected place? for the first line, and I cannot figure out why (I saw https://docs.sqlalchemy.org/en/20/errors.html#error-xd2s as the error pointed out, but I don't get it?

brave bluff
brave bluff
#

So the error is somehow related to lazy loading, but I cannot tell how, given I created the objects at that time:

    user = await register_user(
        email="me@email.com", username="username", password="test1234"
    )
    db_session.add(user)
    await db_session.commit()

    admin_role = Role(name="Admin", owner_id=user.id)
    db_session.add(admin_role)

    user.roles.append(admin_role)
    db_session.add(user)
    await db_session.commit()
brave bluff
#

It as all async issues

#

I had no way of knowing async was problematic

paper flower
#

Perhaps just init it to initial empy array or add default to your mapped_column

#

Also don't commit multiple times during a single operation, or you may only partially commit your data

brave bluff
torn sphinx
#

any spark guides that are not unecessarily confusing and time wasting?

median storm
#

what percentage of people use postgres here? 90%? any love for oracle? 😆

thorny anchor
#

oracle is very good if you need it, but it's very expensive

glacial ether
#

what are the different forms of authentication like making an app and i want to allow people to sign in,i know firebase is prevelant but has to pay is there any way i can do it myself for free?

fervent charm
#

As my table in my duckdb file approaches 40gb, the writes are starting to take a while, is there anything that's similar to duckdb files but more scalable

paper flower
#

https://duckdb.org/docs/guides/performance/file_formats.html#parquet-file-sizes
Recommended file size is up to 10gb, can't you split your data based on something (e.g. date?)

fervent charm
#

I didn't know that, looks like I'll have to split it if I'm to continue using duckdb

coral wasp
paper flower
#

I'm curious what are you using duckdb for? @fervent charm

fervent charm
coral wasp
fervent charm
#

Historical, minute resolution

coral wasp
#

I guess dumb question. Wouldn't be 40gb point in time

paper flower
#

I honestly don't have much experience with timeseries data, but I heard that something like timescaledb could be good, but it depends on how you want to use your data afterwards

fervent charm
#

"Point in time" to me means unrevised. Like at that point in time it was thought that EPS for Q3 for a company was 3.4 but now we know it was really 3.2.

coral wasp
#

Minute resolution data can get problematic to work with.

fervent charm
#

Timescaledb is leagues slower than duckdb. I actually made a video on yt benchmarking this exact thing lol

paper flower
paper flower
#

Ho much data were you inserting?

fervent charm
fervent charm
coral wasp
paper flower
#
    start = time.time()
    df.head(0).to_sql('data_table', pg_engine, if_exists='replace', index=False)

Are you sure this should be in the benchmark?

fervent charm
#

Well the minute level only is still takes up loads

fervent charm
paper flower
#

timescale_benchmark_psy_csv

#

you seem to be loading data from dataframe, don't you think that pandas could be slow instead of timescale itself?

#

Where does df come from in duckdb benchmark?

duck_conn.execute("CREATE TABLE IF NOT EXISTS data_table AS SELECT * FROM df")
coral wasp
#

Yah, would love to see code from those comparisons. Every SWE loves to debate benchmarks

fervent charm
#

Yeah that's definitely possible, maybe I should change the name of the vid to "Benchmarking table-to-datafame operations"

paper flower
#

Honestly to me the benchmark doesn't seem quite correct, you're utilizing duckdb internals to read and load the file into sql, while doing the same with pandas to load data into timescaledb?

#

of course performance could differ wildly here...

fervent charm
coral wasp
#

To_sql isn't the fastest way to load to Postgres

paper flower
fervent charm
paper flower
#

ok, it seems to do some eval/exec magic then

#

But I'd say my point still stands

coral wasp
#

(At least, executemany, but bulk loading is faster)

fervent charm
paper flower
#

Can i get a dataset sample or the code to generate it?

#

Would like to test with sqlalchemy/postgres

coral wasp
#

And, if you're loading to DuckDB, then should be create table xyz as select * from 'myfile.parquet

fervent charm
coral wasp
paper flower
#

Honestly I don't even know how to read parquet files 😅

fervent charm
#

pd.read_parquet(aapl_filepath)

coral wasp
fervent charm
paper flower
fervent charm
#

polars is cool 🐻‍❄️

paper flower
#

Anyway...

coral wasp
fervent charm
#

I am trying to work with polars in rust as we speak lol. The docs are not good.

coral wasp
#

You can load a pyarrow table from parquet, which has the added benefit of zero copy when used in DuckDB or polars (or pandas, if you set the backend/engine to pyarrow)

fervent charm
coral wasp
fervent charm
#

Right, my concern was with the actual .db size potentially getting too big. Or it might be the size of the table that's the problem tbh

#

They don't give you a good way to measure table size

coral wasp
# fervent charm They don't give you a good way to measure table size

Who doesn't? You can list table sizes/etc. https://duckdb.org/docs/sql/meta/duckdb_table_functions.html

fervent charm
normal sentinel
#

How does postgres even work

#

Dont you have to like host a db somewhere and then connect to it

thorny anchor
#

postgres does run as a separate server

cedar tiger
normal sentinel
#

thats pretty dumb tbh

thorny anchor
normal sentinel
#

ik its probably better like that but it just adds another layer of complexity

thorny anchor
#

it has tradeoffs. it's easier to scale, but harder to setup

normal sentinel
#

ig

coral wasp
coral wasp
junior ore
normal sentinel
#

What

glacial ether
#

any free real estate apis
also does the api give pictures or is that not what Apis usually do?

sinful bay
#

Hi Guys I am working on a project API development using FastAPI frameworl and sqlalchemy as a orm tool. sqlalchemy returns a list of row objects, each object is key value pair of its attribute and entry when a query is returned to postman tool it gives response in JSON format. But for join operation sqlalchemy gives list of tuples, each tuple is a key-value pair. How to response this to postman in JSON format?

hushed smelt
#

Hey anyone has idea about datacubes?

#

I want to create a datacube but I see very less resources

#

To learn

wise goblet
#

!rule 6 9 , <@&831776746206265384>

delicate fieldBOT
#

6. Do not post unapproved advertising.

9. Do not offer or ask for paid work of any kind.

formal current
#

This is not a job board, don't post this here please.

jade ledge
#

Yall give me lots of websites in this format:

URL
Name/Title
Description

Give me lots of them, its for a search engine that crawls a database

cinder saffron
#

Lets go my websites DB hit 40GB, just took a year and 46 days

proud stone
#

I'm using SQLite in a Docker container for a simple FastAPI app. Should I be trying to use async/await to access data in SQLite...or am I just asking for trouble

storm mauve
#

you can either use https://pypi.org/project/aiosqlite/ or just use the standard library sqlite3 module, it shouldn't make a difference unless you reach a point in which you shouldn't be using sqlite in first place

proud stone
storm mauve
#

Talking specifically about sync vs async, the amount of time sqlite3 blocks operations for should be trivial

#

In theory the difference should become notable when you have a lot of concurrent requests trying to access the database at the same time, but if that becomes a problem, you should not be using SQLite in first place

proud stone
#

I suspect that I'll never really hit that limit for reads for my needs. I use WAL mode in SQLite to optimize reads + writes.

The trick is that (as I understand it) I'm only using one process?

waxen finch
# proud stone I suspect that I'll never really hit that limit for reads for my needs. I use WA...

even a single process can deadlock itself if it involves multiple connections, although sqlite3 will at least timeout so your program isn't stuck forever: ```py

import sqlite3
conn1 = sqlite3.connect("test.db")
conn2 = sqlite3.connect("test.db")
conn1.execute("CREATE TABLE foo (x)")
conn1.execute("INSERT INTO foo VALUES (1)")

sqlite3 implicitly started a write transaction without committing.

If you unintentionally start another transaction at the same time:

conn2.execute("INSERT INTO foo VALUES (2)")

sqlite3 blocks for 5 seconds before timing out:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
sqlite3.OperationalError: database is locked``` if you're sure you always have no more than one pending transaction on a database, like by using an in-memory db or creating a connection with PRAGMA locking_mode = EXCLUSIVE, then you won't have to contend with locking, but of course, completely preventing concurrent transactions might not be practical for your app

besides that, you can try to be really cautious about how you manage transactions with sqlite3 (for example, never allowing context switches to occur while a transaction is open, and setting timeout=0 to raise "database is locked" exceptions immediately), or you can offload the I/O to a worker thread and let it wait for any locks to be released, which is what aiosqlite does

proud stone
vapid solstice
#

hi

#
import tweepy
from tweepy import OAuthHandler
import pandas as pd

def fetch_tweets(query, count=100):

    # API credentials

    # Authenticate
    auth = tweepy.OAuthHandler(api_key, api_secret)
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth)

    # Fetch tweets
    # lang="en" tells the api to only fetch tweets in english, tweet_mode="extended" tells the api to fetch the full text of the tweets
    tweets = tweepy.Cursor(api.search_tweets, q=query, lang="en", tweet_mode="extended").items(count)
    data = [{"id": tweet.id, "text": tweet.full_text, "created_at": tweet.created_at} for tweet in tweets]
    return pd.DataFrame(data)

if __name__ == "__main__":
    query = "Python programming"
    tweets_df = fetch_tweets(query, 100)
    tweets_df.to_csv("tweets.csv", index=False)
#

i have this code to extract data from twitter

#

i am getting this error

#
  File "c:\Users\McApple\Desktop\Python Projects\twitter_api.py", line 26, in <module>
    tweets_df = fetch_tweets(query, 100)
  File "c:\Users\McApple\Desktop\Python Projects\twitter_api.py", line 20, in fetch_tweets
    tweets = tweepy.Cursor(api.search_tweets, q=query, lang="en", tweet_mode="extended").items(count)
                           ^^^^^^^^^^^^^^^^^
AttributeError: 'API' object has no attribute 'search_tweets'. Did you mean: 'search_users'?
#

can some1 ping me or dm me. Thank You

vapid solstice
#

hello?

umbral glen
#

Check what methods your api has

#

Or try the proposed

winged musk
#

between postgre and mysql which one have better compatiblily with python?

thorny anchor
#

both?

devout maple
#

can I share my simple game that uses sqlite3? I'm learning databases and I'm just using gpt at the moment but I'm onto something I think

#

(learning concepts like ACID and crud, and concurrency but it's too advanced for me)

gritty lark
#

yo how do you hack the nasa?

plucky mist
#

Hello! I had a question! Is better if I use firebase or PostgreSQL with python and docker?

astral shale
#
@app.route('/api/products/updateSize/<int:id>', methods=['PUT'])
def update_size(id):
    product = Product.query.get(id)  # دریافت محصول با شناسه
    data = request.get_json()

    edit_size = data.get("editSize", {})

    for size, stock in edit_size.items():
        product.size_availability[size] = int(stock)
        db.session.commit()
        return jsonify({'message':'successful', 'status':'ok'}), 200
    ```

```py
class Product(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    type = db.Column(db.String(100), nullable=False)
    size = db.Column(db.String(200), nullable=False)
    size_availability = db.Column(db.JSON, nullable=True)  
    stock = db.Column(db.Integer, nullable=True, default=0)
    color = db.Column(db.String(50), nullable=False)
    gender = db.Column(db.String(50), nullable=False)
    image = db.Column(db.String(100), nullable=False)
    price = db.Column(db.Float, nullable=False)


    def __init__(self, name, type, size, size_availability, stock, color, gender, image, price):
        self.name = name
        self.type = type
        self.size = size
        self.size_availability = size_availability  
        self.stock = stock
        self.color = color
        self.gender = gender
        self.image = image
        self.price = price

hello is there anyone to help why when i send request to update_size it doesent change the value in database from frontend sending json data is ok and it sending it with 0 problems. if anyone helps please reply or dm me

coral wasp
#

I didn't look closely but: You have a for loop, but return inside it... so it'd only complete one iteration. .

unkempt drift
#

Can anyone assist me?
I am trying to create a program in python using Sqlalchemy, and also trying to dockerize it. However, I am also told that you should use migrations when using databases. So because of that, I am using alembic.
Using all three components together is very tricky though!
The issue is that I cannot generate the alembic migrations to begin with.
I feel as though when the docker composer is brought up it should run all available migrations and then start the main program. In order to create the migrations I have to do
alembic revision --autogenerate -m "Created state table"
but I feel like this should run on the HOST and not on the docker container itself.
When I attempt to run it on the host, it fails, because the container the mysql database runs on uses a docker container name, which my host doesn't know about.
I have tried asking chatGPT but no matter how I phrase it or what solution it gives me, it violates the basic parameters of this.
anyway, what I got:
Dockerfile:

FROM python:3.9-slim
WORKDIR /server
COPY server/ /server/
RUN pip install --no-cache-dir sqlalchemy pymysql alembic
COPY alembic /server/alembic/
COPY alembic.ini /server/alembic.ini
CMD ["sh", "-c", "alembic upgrade head && python -u main.py"]

docker-compose.yml:

services:
  db:
   image: mariadb:10.5
   container_name: db_test
   environment:
     MYSQL_ROOT_PASSWORD: password
     MYSQL_DATABASE: game
     MYSQL_USER: user
     MYSQL_PASSWORD: password
   ports:
     - "5101:5101"
   volumes:
     - mariadb_data:/var/lib/mysql

  server:
    build: .
    container_name: game_test
    ports:
      - "5100:5100"
    depends_on:
      - db
    #restart: on-failure
  migrations:
    build:
      context: .
    container_name: alembic_migration
    depends_on:
      - db
    environment:
      SQLALCHEMY_URL: mysql+pymysql://user:password@db_test/game
    command: alembic upgrade head
volumes:
  mariadb_data:
#

server/main.py:

import time
from sqlalchemy import create_engine, Column, String, Integer, MetaData, Table
from sqlalchemy.orm import declarative_base, sessionmaker
Base = declarative_base()
metadata = MetaData()

class Foo(Base):
    __tablename__ = "foo"
    id = Column(Integer, primary_key=True, autoincrement=True)
    bar = Column(String(50), nullable=False)
    fruit = Column(String(10), default="banana")
    veggie = Column(String(10), default="broccoli")
DB_USER = "user"
DB_PASSWORD = "password"
DB_HOST = "db_test"
DB_NAME = "game"
DATABASE_URL = f"mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}/{DB_NAME}"
print(DATABASE_URL)
time.sleep(3)
engine = create_engine(DATABASE_URL, echo=True, connect_args={"charset": "utf8mb4"})
Base.metadata.create_all(engine)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
with SessionLocal() as session:
    print(session)
    new_row = Foo(bar="baz")
    session.add(new_row)
    session.commit()
    print("table created")

alembic.ini

alembic]
script_location = alembic
prepend_sys_path = .
version_path_separator = os  # Use os.pathsep. Default configuration used for new projects.
sqlalchemy.url = ${SQLALCHEMY_URL}
[post_write_hooks]
[loggers]
keys = root,sqlalchemy,alembic
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
qualname =
[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
[logger_alembic]
level = INFO
handlers =
qualname = alembic
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
#

directory listing:

(.venv) [sean@arch dockertest3]$  (master)tree
.
├── alembic
│   ├── env.py
│   ├── __pycache__
│   │   └── env.cpython-313.pyc
│   ├── README
│   ├── script.py.mako
│   └── versions
├── alembic.ini
├── commands
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
└── server
    ├── main.py
    └── __pycache__
        └── main.cpython-313.pyc
#

Please let me know if I'm going about this completely the wrong way. I am quite lost and frankly a little frustrated.

unkempt drift
#

Should I just not create migrations at all?

echo wadi
#

Need help with mysqldump on Mac Terminal

lethal swan
celest zodiac
echo wadi
#

I am migrating to a new laptop, and I want to backup my current website and database (MySQL). I have an old script that worked fine before in Mac Terminal, but I am getting an error. (Have been "Spring cleaning" and changed the filings tructure, but that shouldn't matter.)

#

I get this error in Terminal...

#

zsh: command not found: mysqldump

#

Here is my command string....

#

/Applications/MAMP/Library/bin/mysqldump --skip-extended-insert --host=localhost -uroot -p db_dev > '/Users/user1/Documents/4 - INFORMATION TECHNOLOGY/4 - DEVELOPMENT/DB_BACKUPS/db_dev_2024-12-31_0927.sql'

paper flower
celest zodiac
#

is there mysqldump in /Applications/MAMP/Library/bin?

echo wadi
#

Yes

celest zodiac
#

try changing into that directory and running it without the path
e.g. mysqldump --skip-extended-insert --host=localhost -uroot -p db_dev > '/Users/user1/Documents/4 - INFORMATION TECHNOLOGY/4 - DEVELOPMENT/DB_BACKUPS/db_dev_2024-12-31_0927.sql'

echo wadi
#

Rusty on command line.... How do I do that? cd /Applications/MAMP/Library/bin

celest zodiac
#

I think so, what happens when you do that?

echo wadi
#

I see bin %

celest zodiac
#

and ls gives you what?

echo wadi
#

zsh: permission denied:

celest zodiac
#

ok, there may be a permissions issue going on here. I don't have enough Mac experience to know really

echo wadi
#

A whole bunch of programs including mysqldump

#

The only thing that changed is where I store files

#

Could spaces cause issues?

celest zodiac
#

you have the path quoted, but I don't know if that's how zsh handles paths with spaces in them

echo wadi
#

Like... '/Users/user1/Documents/4 - INFORMATION TECHNOLOGY/4 - DEVELOPMENT/DB_BACKUPS/db_dev_2024-12-31_0927.sql'

#

Let me try something...

#

Just tried...

#

/Applications/MAMP/Library/bin/mysqldump --skip-extended-insert --host=localhost -uroot -p db_dev > '/Users/user1/Documents/db_dev_2024-12-31_0927.sql'

#

Am looking at this now...

#

(I am totally not a command-line kind of person)

#

Because this is a utility for MySQL, I'm leery to start changing file permissions

celest zodiac
#

yeah, I'm not a Mac guy, but I will say that learning more about the command line on whatever platform you use is vital for this kind of work

echo wadi
#

Could it be a corrupt OS? (One reason I am trying to get everything of fthis old MBP before year's end (~ < 12 hrs) is because the logic booard is toast

#

But other than rearranging my folders, nothing else has changed, and I just copied and pasted the old command - changing paths - which worked a couple years ago

celest zodiac
#

I don't have enough Mac experience to help with that, sorry

echo wadi
#

Are you proficient with Linux or even Windows command line?

celest zodiac
#

yes, but the Mac is very much its own animal.

echo wadi
#

maybe not

#

I had this really strange issue a couple years ago where I couldn't get MAMP working. And after like a week of researching, I had to do this...

#

(Lost my command history)

#

su user2

#

can't find other commands, but yoyo mysql

#

The point being maybe I am logegd in as Admin (user2) now and that is causing issues?

celest zodiac
#

I don't know. I don't know enough about the Mac to say.

echo wadi
#

How would you un sudo yourself back into the current account?

celest zodiac
#

I don't know.

#

The only thing I can think of would be to close the current terminal session

echo wadi
#

TADA

#

su user1

#

That was the issue

celest zodiac
#

ok, so it was permissions!

echo wadi
#

More so that I was still logegd in as user2 (admin)

#

Crap, now I last my saved commands

#

At least mysqldump is working

#

Must be your presence that inspired me! 😉

celest zodiac
#

Glad I was of some help, even if I have no Mac experience as such

echo wadi
#

Sometimes thinking out loud talking with someone else about unrelated things triggers the brain

#

I just want to get my life off this old MBP and onto my new MBP so I can get to Python soon!

celest zodiac
#

Rubber Duck Debugging

echo wadi
#

What's that?

celest zodiac
#

exactly what you described! :D

#

In software engineering, rubber duck debugging (or rubberducking) is a method of debugging code by articulating a problem in spoken or written natural language. The name is a reference to a story in the book The Pragmatic Programmer in which a programmer would carry around a rubber duck and debug their code by forcing themselves to explain it, l...

echo wadi
#

PRICELESS!!!

#

(How old are you, if I can ask?)

celest zodiac
#

52

echo wadi
#

Cool

#

I'll be 54 soon

#

Thanks for the term and link

#

Now that my computer is Feng Shui'ed, I can file that away and actually refer to it

#

As I was doing that, I stumbled across some old stuff which took me online which lead me to find out that some really knowledgeable people I knew online had died

celest zodiac
#

note that if we're done with this we should let the channel go back to topic, we try to keep the channel discussions focused on the topic at hand

echo wadi
#

Itw as a start reminder of how little time I have left

#

Okay, was just saying that I appreciate "older" people who know about terms like you posted

#

When all of these people die off, so much knowledge is going to get lost

#

(I'll be sure to file away as much as I can while people like you are around!)

#

Thanks!

#

BTW...

#

This is what caused the earlier issue

#

su user2
sudo /Applications/MAMP/bin/stopApache.sh
sudo /Applications/MAMP/bin/startApache.sh

#

(I need to do that - annoyingly - everytime I launch MAMP so it works because there is something broken on this old Mac...)

fringe stone
#

Is there any reason why a local postgres instance might be taking exactly 60 seconds to connect?

#

the database tool in my IDE (IntelliJ) connects instantly without any issues.

#

I have the service defined in a docker-compose:

  postgres:
    image: postgres:15-alpine
    container_name: database
    environment:
      POSTGRES_USER: DEVELOPMENT
      POSTGRES_PASSWORD: DEVELOPMENT
      POSTGRES_DB: facadectl
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
#

I think IntelliJ uses the jdbc driver

#

I should also mention that it eventually succeeds, but it just takes outrageously long to connect

paper flower
fringe stone
paper flower
#

But what exactly are you doing? It's very difficult to tell what's wrong without any code

fringe stone
#

Same issue though. It takes 60 seconds to connect. I've provided basically all of the relevant code.

paper flower
#

Huh, that's weird... I'm not at PC right now, but can try to reproduce it when I can

fringe stone
#

I've just resorted to sqlite for now

paper flower
#

Maybe pithink, I never had such issue tbh

echo wadi
#

Hi. I need some help with MySQL on my Mac. In the process of migrating everything over from my old MBP to a new MBP, and it appears that I broke MySQL and/or phpMyAdmin 😭

#

Command-line is not my thing, and so I'm flailing right now. (Damn! And I wanted to have my migration done by 2025!)

echo wadi
#

Where to begin? Okay so I am migrating from this old MBP to a new MBP. (Wanted to haev it done by 2025, but that isn't looking likely.)

#

I use MAMP for my webserver and MySQL server and phpMyAdmin to adminster things.

tawny orchid
#

m apache m php something?

echo wadi
#

I am here because I want to learn Python and replace this old site with a new one, but first i need to get my old dev environment and website working on my new Mac

#

Mac Apache MySQL PHP

tawny orchid
#

okkay :>

echo wadi
#

So after I installed MAMP on my new MBP, I spent a lot of time tweaking config files to supposedly make MAMP work. (I put in a bunch of dummy placeholder files in various directories so I know here to update stuff. Have been using MAMP for like 15 yrs)

#

Updating things like the php.ini is a bitch, but I am experienced with things

#

Oh, I was able to get my old website working on this old MBP using MAMP so I know my code and db work

#

So anyways - sorry but this is complicated

#

I was ready to launch my website on my new MBP and I got some errors in FireFox.

#

It said the table that I wrte errors to was missing - because I had some PHP errors to because of the newer install

#

So, when I go into phpMyAdmin, I see all of my tables

tawny orchid
#

did you typo the database name in the connection string? 😮

#

i guess not

echo wadi
#

BUT when I clicked on the log_view_page table phpMyAdmin says... #1146 Table 'db_dev.log_view_page' doesn't exist

#

Here is what I am wondering...

#

(Sorry, I am going back and forth between two laptops in the front seat of my car in the dark!)

#

I just copied the directory that supposedly holds my database from old to new laptop

tawny orchid
#

you should probably take a dump!

#

mysqldump -u [username] -p [database_name] [other_database_name] -R -e --triggers --single-transaction > database_backup.sql

echo wadi
#

I see all of these files - with filesizes larger than 0 - on my new laptop, so the database should be there, but maybe you can't just copy and paste a database like that?

#

You have to understand that life came up and I havent done any of this in 10 years...

#

I just want to get my old dev environment and website working so I can quickly pivot to coding a new website

tawny orchid
#

i don't know. Maybe it works, maybe not 😄 But taking a dump is the way a backup is meant to be taken

echo wadi
#

Do you think copying and pasting is the issue?

tawny orchid
#

might be, and if I had to guess, it's because of it

#

but as i said, idk

echo wadi
#

I have that command saved into a file for reference, but I didn't use in in my new install of MAMP because I thought it maybe only exported the data and not the database structure?

tawny orchid
#

it takes switches for what you want the dump to contain

#

see --help of it

echo wadi
#

This is what I had in notes...

#

/Applications/MAMP/Library/bin/mysqldump --skip-extended-insert --host=localhost -uroot -p db_dev > '/Users/user1/Documents/some_path/db_dev_2024-12-31.sql'

#

Dont recall if that was just data only of the DDL or whatever as well

#

If I move the copied directory to the side, will it interfere with trying mysqldump?

tawny orchid
#

idk, i don't think so.

#

copied directory to the side? 😮

echo wadi
#

I Googled the error and one site said it was just a permissions issue

tawny orchid
#

okkay

#

sorry for wasting your time, then 😄 My guess was wrong

echo wadi
echo wadi
#

(I can''t have two laptops in one lap)

#

One site suggested running SHOW TABLES

#

But I cant figure out how to get the MySQL prompt in Mac Terminal for MAMP

tawny orchid
#

write mysql?

echo wadi
#

Could you help me figure that out? (Because first I need to prove if the tables exist or not in mysql)

tawny orchid
#

type mysql -h

#

-h was hostname

#

not help

#

--help switch is help

echo wadi
#

Before doing that, I tried this..

#

/Applications/MAMP/Library/bin/mysql -uroot -p

#

And get Enter password

#

But then I get

#

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)

#

Your suggestion yields

#

zsh: command not found: mysql

#

mysql -h

tawny orchid
#

nm 😄 You explained it cannot connect

#

ps axu| grep mysql

#

is the server running?

#

also, you can give it hostname and port to connect via tcp

echo wadi
#

Another site said to yo yo MySQL. Maybe I broke it?

tawny orchid
#

mysql -u root -p -h 127.0.0.1 -P 3306

#

check the switches

#

that they're correct

#

with mysql --help

echo wadi
#

user1 1628 0.0 0.0 34122828 836 s000 S+ 9:36PM 0:00.00 grep mysql

tawny orchid
#

that's the only row?

echo wadi
#

yes

tawny orchid
#

seems your mysqld isn't running?

#

try start up your server

echo wadi
#

I had MAMP off

#

Try that command again?

tawny orchid
#

sure

echo wadi
#

user1 1763 0.0 1.1 34542240 180264 ?? S 9:37PM 0:00.41 /Applications/MAMP/Library/bin/mysqld --basedir=/Applications/MAMP/Library --datadir=/Applications/MAMP/db/mysql57 --plugin-dir=/Applications/MAMP/Library/lib/plugin --log-error=/Applications/MAMP/logs/mysql_error.log --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --socket=/Applications/MAMP/tmp/mysql/mysql.sock --port=3306
user1 1649 0.0 0.0 34134512 1420 ?? S 9:37PM 0:00.03 /bin/sh /Applications/MAMP/Library/bin/mysqld_safe --port=3306 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error.log

tawny orchid
#

then try with mysql -u root -p

echo wadi
#

I'm on my old laptop now

#

(getting confused quickly)

tawny orchid
#

okkay. So you want to take the dump?

#

or?

echo wadi
#

When I launched MAMP, and I go into NetBeans to run my website, it should work because I got it working yesterday on my old laptop

#

But when I launch it in NetBeans, I get this in Firefox

#

Forbidden

You don't have permission to access this resource.Server unable to read htaccess file, denying access to be safe

#

WTF?

#

Now I have two broken laptops?

tawny orchid
#

.htaccess is a apache thing

echo wadi
#

(I don't have Discord set up on my new laptop yet)

tawny orchid
#

did you tinker apache to run under different user or did you change the files it serves any way? The running web-server process may not have permissions to read the .htaccess (is my guess)

echo wadi
#

Disregard last comment. My old laptop and MAMP are screwed up and to get things to work I have to su user and then yo-yo Apache

#

So my website IS working again on this old laptop

#

But I cannot seem to get phpMyAdmin to work

#

And I was trying your commands here, because the end goal is to see if I have tables in MAMP's MySQL

tawny orchid
#

that.... i don't know. I don't really know apache nor phpmyadmin

echo wadi
#

So what works here should work on my new laptop, right?

tawny orchid
#

yes, if the database is ok, and you dump everything it should work

echo wadi
#

And since I know my website works here, then if I can figure out how to SHOW TABLES in Terminal, then I can use that on my new laptop to verify if they are there

tawny orchid
#

btw do you know homebrew

#

just a side comment

echo wadi
#

No, but I need to learn how to use it with 10,000 other things!

tawny orchid
#

no. I was hoping it might make your life easier, but it's not a requirement for anything

echo wadi
#

I'm nervous about mysqldump because I dont think it's so easy to copy over all the db objects as one might think

tawny orchid
#

it's purpose built for that.

echo wadi
#

How would Homebrew help here?

tawny orchid
#

mmm... it's a package manager. It's easy to install database, web server and python with it

echo wadi
#

After 10 years off, I don't remember what it does and doesnt do, but I know my db has stored procedures and trigegrs and I'm afraid of breaking any of this since I feel like I have Windows 95 and no tech support!

tawny orchid
#

you need to dump those also

#

check the switches, and make sure you select everything you need to dump

#

mysqldump --help

echo wadi
#

If I opened a backup I already did, would it help me determine if it backs up the db objects too?

tawny orchid
#

you can just open the .sql file and check what it inserts, that it defines triggers and procedures and views and whatnot

#

after dumping

#

and if you missed some, you can do again

#

and if you notice after loading the dump onto the new macbookpro that you missed something, you can still go back and do a dump

echo wadi
#

So you know MySQL?

tawny orchid
#

a little. We had a course using mariadb at school, but i use postgres more

echo wadi
#

What keyword would be used for Triggers and Stored procedures?

tawny orchid
#

i don't remember. Lemme check ;D

#

you can search for create procedure for procedures

echo wadi
#

I see this...

tawny orchid
#

replace procedure with create trigger

echo wadi
#

/!50003 CREATE/ /!50017 DEFINER=root@localhost/ /!50003 TRIGGER checkAddArticle BEFORE INSERT ON article_placement FOR EACH ROW BEGIN
SELECT COUNT(
) INTO @sdCount
FROM section_dimension
WHERE section_slug = NEW.sd_section_slug
AND dimension_slug = NEW.ds_dimension_slug;

IF @sdCount = 0 Then
INSERT INTO invalid_section_dimension_pair
VALUES(null);
END IF;

SELECT COUNT(*) INTO @dsCount

FROM dimension_subsection
WHERE dimension_slug = NEW.ds_dimension_slug
AND subsection_slug = NEW.ds_subsection_slug;

IF @dsCount = 0 Then
INSERT INTO invalid_dimension_subsection_pair
VALUES(null);
END IF;
END */;;
DELIMITER ;

#

That is my code for sure, but it almost looks like it is commented out?

tawny orchid
#

did you use switch --triggers

echo wadi
#

2025

tawny orchid
#

btw, you can paste code with triple-backticks and have syntax hilighting by using the lang after. ```sql select 1 ```

echo wadi
#

Back, just dictated a quick note to myself on my iPhone for New years

echo wadi
tawny orchid
#

then the dump won't include triggers

echo wadi
#

But is that not my trigger above?

#

/Applications/MAMP/Library/bin/mysqldump --skip-extended-insert --host=localhost -uroot -p db_dev > '/Users/user1/Documents/db_dev_2021-02-18_2033.sql'

#

That is from 4 years ago

tawny orchid
#

i don't know why it works like it does. But if it is commented out it probably is ignored when the dump is loaded

#

you want everything, right?

echo wadi
#

Everything

tawny orchid
#

--routines for routines, --triggers for triggers ... Maybe something else too? Or not? You probably know. Also double check those, i dont have mysql installed, so i check the switches from webs

echo wadi
#

Anyone here that might know phpMyAdmin?

#

Sounds like you think my copy & paste is the issue even though I have all of the db files, right?

tawny orchid
#

i think it might be. I don't know. It's merely a guess

#

but i do know that dumping is made for backing stuff up

echo wadi
#

I'm just scared of mysql dump because I dont recall what all my website and database did. And the goal is to just get it migrated so I have it as a working reference when I build my new site using Python

#

I guess I can Google the topic more tomorrow and maybe someone has written an article or YT video on how to back up everything

tawny orchid
#

sure

echo wadi
#

I thought the backups I did in the past worked, but I dont remember

#

I gotta head home

#

Thanks for trying to help, and I hope I dont break things

tawny orchid
#

i hope you get it working, and good luck :>

echo wadi
#

It's always one last details that breaks things!

#

I'll be back tomorrow. Thanks for the help and Happy 2025!

tawny orchid
#

Happy new year to you aswell!

pearl storm
#

I'm interested in making my own database framework what makes a database framework like NoSQL scalable

echo wadi
#

Need help navigation Mac Terminal and trying to see if my database tables are there after a migration

echo wadi
#

I was able to figur eout the corrcet path to run mysql in Terminal. Now I could use some advice from someone who is experienced using mysqldump

echo wadi
#

I fixed it without needing mysqldump. Turns out there were like four files starting with ib_ in Applications > MAMP > db > mysql57 that I didn't bother to copy over, but which phpMyAdmin needed. Web legacy website is now working on my new laptop!! YEAH!!!

winter burrow
#

rewriting my old sql3 wrapper and i rll like how its turning out rn, any tips?

#

might make it open-source

#

it does recognise tables and all that for you as well as primary keys so something like

with data.open() as db:
  db["yourTable"].findFirst(primaryKey)

would work just fine

#

also gonna add db.pause and db.resume to commit and close the db for a larger computations without making a new db object

young atlas
#

confused on how to link a db to a discord bot that my friend allowed me to use; running off replit and a vps

winter burrow
young atlas
#

mobile

#

legit nothing else to use is there

winter burrow
#

and wdym by linka a db

#

what type of db and where is it hosted

young atlas
#

let me check

#

i made one but idk how to set it up

#

PostgreSQL, supabase

winter burrow
#

search up documentation, i dont use postgres

young atlas
#

fuck

cedar tiger
torn sphinx
winter burrow
fervent charm
#

Yall, do not try to do parallel writes to duckdb files, with time.sleep and stuff. It'll end with a corrupted db

heavy swift
#

what should i name a db column having number of pages in a book? num_pages, pages, page_count... anything else? its in a table called books.

fervent charm
#

I like page_count

cedar tiger
#

When I tried to backup my database from a local postgresql container for my django project, I wanted to test the backup sql script by putting it up on Supabase. I found that the pg_dump uses stdin and then inserts each row into the table as opposed to using INSERT.

I used docker-compose exec -T postgres pg_dump -U postgres -d mydjangosite > backup.sql

How do I change this so that I can have a working backup sql script?

bitter flax
#

add --inserts for INSERT INTO on each line I think

bitter flax
cedar tiger
cedar tiger
coarse crown
#

hi guys, I want to extract this table to a personel spreadsheet. How can I do that?

thorny orchid
#

if a client has a post request that gives the entire blocked and friends lists, would it be ok to store this in my database on the user table as a json array, or should i make a seprate table for friends and blocked users

coral wasp
#

(Assuming it's on some webpage)

fading patrol
fervent forge
#

Anyone tried switching from psycopg2 to asyncpg, and then getting "another command is already in progress" errors, which did not happen with psycopg2?

paper flower
fervent forge
#

@paper flower yes, but the thing is, it has always worked perfectly with psycopg2, but after switching to asyncpg, the issues show up.

This issue appears during tests (using pytest) , where around 5% will now fail.

Just seems strange that psycopg2 had no issues with this 🤔

paper flower
digital sequoia
#

how would you lot check if a folder is changed?

#

would you check everytime the program is loaded? or would you do it everytime its loaded at a certain time with an option to reload?

#

its a huge folder, im looking for specific filetypes, and im looking in 4 specific folders

#

got it, store len(gdt_files)

then scandir, len([entry for entry in os.scandir

if len == stored len

thorny anchor
#

do you need to know when a file is modified?

digital sequoia
wise goblet
wise goblet
digital sequoia
#

os.walk laggy

wise goblet
digital sequoia
#

It's the os.walk that lags

#

Not dumping it to a table or json

wise goblet
digital sequoia
#

I need to walk 4 folders look for *.gdt and dump their filepaths to

gdt[mainpath]

wise goblet
#
pip install watchdog[watchmedo]

watchmedo auto-restart --patterns "*.templ;*.go;*.css;*.js;enverant.json" -i "*_templ.go" --recursive -- sh -c "task web; sleep infinity"
#

i can specify which file patterns to listen, and any arbitary command to run on file changes

#

^_^

#

my favourite thing for dev env

#

task web; sleep infinity is the arbitary command running on file changes

digital sequoia
#

Ok, gotta find a model viewer now

#

Might write my own

#

Turns verts and indices into a mesh

heavy socket
#

I'm just getting started using sqlalchemy for the first time (I'm very familiar with Django ORM). I have some dataclasses that I'd like to use "as is" with sqlalchemy, but the docs seem to imply that I should use MappedAsDataclass, which to me means that I should define them as sqlalchemy objects instead of as dataclasses. Is that the correct way to go about this? I was hoping there was just an easy wrapper I could put ontop of a dataclass lol 🤷‍♂️

urban minnow
#

anyone out here who could help me in a small problem im facing????

basically this a school assignment of mine and apparently i had to rewrite a to-do list program with mysql connectivity integration.

#

i need to know how can i make the sql command so that whenever a task is entered , it auto numbers them , aka automatically assigns the primary key id numbers

#

the table structure is (id int primary key , task varchar(50))

#
def add_task():
    task = input("Enter the task: ")
    b = connect()
    c = b.cursor()
    c.execute("INSERT INTO tasks (task) VALUES (%s)", (task,))
    b.commit()
    print(f'Task "{task}" added!')
    b.close()
#

part of the code im struggling with

#

like when i enter a task say do chores , it should execute
c.execute("INSERT INTO tasks (task) VALUES (1, 'do chores')")
and when i input another tasks , do homework , it should automatically assign it the next number for the id

#

like c.execute("INSERT INTO tasks (task) VALUES (2, 'do homework')")

#

do ping if any of yall help

analog sigil
analog sigil
urban minnow
# analog sigil `ALTER TABLE tasks MODIFY id INT AUTO_INCREMENT;` This will modify your table s...

one small issue , while this does works fine , but my program also has a delete tasks function which removes the selected task (row) from the table , and when i do so , the next task entered has the next sequential number assigned to id
say task1 was entered , it got assigned id = 1
i deleted task1 , no more tuples in the table
i add a new task 'task2' , but this time the id=2 when it should have been 1 cuz this is the first and only tuple present in the table

#
def remove_task():
    view_tasks()
    try:
        task_id = int(input("Enter the task number to remove: "))
        b = connect()
        c = b.cursor()
        c.execute("DELETE FROM tasklist WHERE id = %s", (task_id,))
        if c.rowcount > 0:
            print(f'Task with ID {task_id} removed!')
        else:
            print("Invalid task number.")
        b.commit()
        b.close()
    except ValueError:
            print("Please enter a valid number.")
#

this is the remove task function in my program

echo drift
#

Which database is best for linux operation system with alot of requests

wise goblet
#

fitting 95%+ usage cases

#

majority of people have no chances to reach its limits

echo drift
#

Ok thx

thorny anchor
urban minnow
thorny anchor
#

so all the task ids will "slide up"?

urban minnow
#

Yes

thorny anchor
# urban minnow Yes

i see. a row's primary key should not change, so instead we will just use a different mechanism for numbering the tasks and keep the id column as it is

#

do you need the numbering to be done in the database itself?

grim vault
#

!e If you let the database do it, t3 will have id 3.

import sqlite3

conn = sqlite3.connect(":memory:")
conn.execute("create table tasks(id integer primary key, name text)")
conn.execute("insert into tasks(name) values (?), (?)", ("t1", "t2"))
print(conn.execute("select * from tasks").fetchall())
conn.execute("delete from tasks where name = ?", ("t1",))
conn.execute("insert into tasks(name) values (?)", ("t3",))
print(conn.execute("select * from tasks").fetchall())
delicate fieldBOT
grand niche
#

Hello everyone!
For the past few months, I've been working on ORMagic - a simple, fast, and lightweight ORM for Python, built on top of Pydantic .

Today, I'm excited to announce a major update that adds PostgreSQL integration!

The main goal of ORMagic is to provide a simple and easy-to-use ORM for Python, that is easy to understand and use, while still providing the necessary features to interact with a database.
Is based on the Pydantic model and extends it with the ability to interact with SQLite and PostgreSQL databases.

Simple example

from ormagic import DBModel

class User(DBModel):
    name: str
    age: int

User.create_table()

User(name="John", age=30).save()

User.get(name="John")
>>> User(id=1, name='John', age=30)

You can find more examples and detailed documentation at spaceshaman.github.io/ORMagic/

If you like the project, please give it a star on GitHub: https://github.com/SpaceShaman/ORMagic

I also welcome any feedback or suggestions, so feel free to open an issue. The project is open to pull requests as well!

Thank you for your support!

cedar tiger
wise goblet
# grand niche Hello everyone! For the past few months, I've been working on [ORMagic](https://...

There is somewhat known (15k stars) ORM SQLmodel from fastapi creator
That uses Pydantic centric approach too

Could be good to know your project difference from it
https://github.com/fastapi/sqlmodel
What is your project brings unique new to the table in comparison and having it written in docs

GitHub

SQL databases in Python, designed for simplicity, compatibility, and robustness. - fastapi/sqlmodel

wise goblet
paper flower
#

I don't think there's any benefit in adding pydantic to orm(s)

wise goblet
paper flower
#

It covers a lot of use cases, there certainly isn't a lack of documentation

paper flower
#

Regarding typing I there's still isn't a reason to use pydantic, even it's __init__ is using mypy plugins to get proper typing 🤔 On the other hand it shouldn't be difficult to use dataclasses or dataclass_transform like sqlalchemy does

grand niche
# wise goblet There is somewhat known (15k stars) ORM SQLmodel from fastapi creator That uses...

I know SQLModel and I don't really want to compete with it (for now I develop ORMagic alone in my free time, just for fun). The main difference between these two libraries is a different approach to the API which seems more intuitive to me, in ORMagic all interactions with the database take place using classes defining models (similar to Django but with better type annotation thanks to the use of Pydantic models), in addition I try to make my library have as little dependency as possible (in the case of the basic version without Postgres, it only depends on Pydantic)

grand niche
paper flower
urban minnow
paper flower
#

How many records would you have?

urban minnow
#
import mysql.connector as a
def connect():
 return a.connect(host='localhost', 
user='root', 
password='upps', 
database='todo_list')
def display_menu():
 print("\nTo-Do List Menu:")
 print("1. Add Task")
 print("2. View Tasks")
 print("3. Remove Task")
 print("4. Exit")
def add_task():
 task = input("Enter the task: ")
 b = connect()
 c = b.cursor()
 c.execute("INSERT INTO tasklist (task) 
VALUES (%s)", (task,))
 b.commit()
 print(f'Task "{task}" added!')
 b.close()
def view_tasks():
 b = connect()
 c = b.cursor()
 c.execute("SELECT id, task FROM tasklist")
 tasks = c.fetchall()
 if not tasks:
 print("No tasks in the list.")
 else:
 print("\nYour Tasks:")
 for task_id, task in tasks:
 print(f"{task_id}. {task}")
 b.close() 
def remove_task():
 view_tasks()
 try:
 task_id = int(input("Enter the task number to 
remove: "))
 b = connect()
 c = b.cursor()
 c.execute("DELETE FROM tasklist WHERE 
id = %s", (task_id,))
 if c.rowcount > 0:
 print(f'Task with ID {task_id} removed!')
 else:
 print("Invalid task number.")
b.commit()
 b.close()
 except ValueError:
 print("Please enter a valid number.")
 
def main():
 tasks = []
 while True:
 display_menu()
 choice = input("Choose an option (1-4): ")
 
 if choice == '1':
 add_task()
 elif choice == '2':
 view_tasks()
 elif choice == '3':
 remove_task()
 elif choice == '4':
 print("Exiting the To-Do List. Goodbye!")
 break
 else:
 print("Invalid choice. Please try again.")
paper flower
#

Could you explain what are you trying to do and why you want to remove gaps from the sequence?

tropic mesa
#

how do i restore a db?

finite cobalt
#

Uhh 😬

grizzled sequoia
#

It helps to give more context around the situation.

hasty ore
#

Could some one point me in the direction of a good guide to explain Cartesian join or table joins . I’m having troubles figuring out how it if you join two table with different amounts of columns . How can a single table be created then with no empty spaces .

thorny anchor
#

the number of columns isn't important, if you join a table (A, B) with (B, C, D), the result will just be (A, B, C, D)

grim vault
# thorny anchor the number of columns isn't important, if you join a table `(A, B)` with `(B, C,...

!e I think that's join and database dependent, eg SQLite:

import sqlite3

conn = sqlite3.connect(":memory:")
conn.execute("create table table1(a,b)")
conn.execute("insert into table1 values('a','b')")
conn.execute("create table table2(b,c,d)")
conn.execute("insert into table2 values('b','c','d')")

# double B
print(conn.execute("select * from table1, table2").fetchall())
print(conn.execute("select * from table1 join table2").fetchall())
print(conn.execute("select * from table1 join table2 on table1.b = table2.b").fetchall())
print(conn.execute("select * from table1, table2 where table1.b = table2.b").fetchall())

# single B
print(conn.execute("select * from table1 join table2 using(b)").fetchall())
print(conn.execute("select * from table1 natural join table2").fetchall())
delicate fieldBOT
thorny anchor
#

but yeah I should have clarified. if you were joining on B you get that result. in general you'd get B twice

hasty ore
#

I’m fairly new so I’m still trying to grasp the concepts . I’m using phpMyadmin for a course and how it was presented was :

#

How then is a new table created with no missing information . If table 1 has 3 columns and table 2 has 11 columns . Shouldn’t there be empty spaces where table one column does not have information for?

#

Sorry for the confusion

thorny anchor
steady shard
#

Azure Cosmos DB Conf 2025
April 15th 2025, virtual conference.
Call for Proposals is now open until Feb 25. https://aka.ms/CosmosConfCFP

Azure Cosmos DB Conf is a free virtual developer event co-organized by Microsoft and the Azure Cosmos DB community. This is our fifth Azure Cosmos DB Conf. Sessions will be a combination of Microsoft and community delivered. Come and learn more about Azure Cosmos DB. See what others in the community are building.

viral tapir
#

hm

tacit veldt
#

try to Add a locked field to the coinflips schema to mark whether a coinflip is being modified
like

locked: { type: Boolean, default: false },```
plucky shell
#

isnt that good?

tacit veldt
#

and then like Modify your cancelcoinflip Similarly

#

hm

#

go dms

hardy agate
#

Hey guys, good afternoon. I have the following situation:

I need to create a django API from a database made in postgresql 12.4. The thing is: the only version that supports postgresql 12.4 is django 4.1. What can i do?

Using django 4.1 and not the latest version can be a problem? in terms of features of django?

Exceptions:
I cant upgrade the database because is an active database (its on production in odoo 12 so it will be imposible unless i try to upgrade odoo which isnt going to happen)

cyan dirge
#

Hey guys, one question, why when creatin geometry point like this in pgadmin

SET alberghi_location = ST_GeomFromText('POINT(' || Longitudine || ' ' || Latitudine || ')', 4326);```
#

I still get data like this 0101000020E61000005803EF3F0D6E3140C1C9FE2957584440

#

and not in this format "POINT(17.429889675 40.6901600355227)"

unkempt drift
#

hi guys, quick question.
in models.py for sqlalchemy

lass KnownPlanets(Base):
   __tablename__ = "known_planets"
   user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
   planet_id = Column(Integer, ForeignKey("planets.id"), primary_key=True)
   __table_args__ = (
       #TODO: a primary key for two columns doesn't work
       #PrimaryKeyConstraint("user_id", "planet_id", name="pk_known_planets"),
       PrimaryKeyConstraint("user_id", "planet_id"),
       {"mysql_collate": "utf8mb4_unicode_ci"},
   )

when I run "SHOW CREATE TABLES known_planets" in the sql command line:

 known_planets | CREATE TABLE `known_planets` (
  `user_id` int(11) NOT NULL,
  `planet_id` int(11) NOT NULL,
  KEY `user_id` (`user_id`),
  KEY `planet_id` (`planet_id`),
  CONSTRAINT `known_planets_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
  CONSTRAINT `known_planets_ibfk_2` FOREIGN KEY (`planet_id`) REFERENCES `planets` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |

So the two keys I had set explicitely to be primary keys are both marked as simply "KEY".
This makes it so if I insert an entry that has the same (user_id, planet_id) as an entry that already exists, it inserts it anyway.
chatgpt and various resources online tell me it should prevent it.

When creating the table from the command line, I can create composite keys just fine, and duplicate entries aren't being created so it's not an issue with the version of mariadb I'm running.

Goal: create a composite key with sqlalchemy
Issue: I can't, and duplicate entries are being created

What am I doing wrong?

paper flower
unkempt drift
#

alembic

paper flower
#

Could you share the migration file?

unkempt drift
#

uhh I am really, really bad with alembic (I had just fixed an issue i had for the past there weeks)

#

i can try?

#

this?

"""changed primary key of knownplanets

Revision ID: 6444b4b10c02
Revises: e137714a90f8
Create Date: 2025-01-18 00:16:34.075779

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision: str = '6444b4b10c02'
down_revision: Union[str, None] = 'e137714a90f8'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('known_planets', 'user_id',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=False)
    op.alter_column('known_planets', 'planet_id',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=False)
    op.drop_index('ix_known_planets_id', table_name='known_planets')
    op.drop_column('known_planets', 'id')
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('known_planets', sa.Column('id', mysql.INTEGER(display_width=11), autoincremue, nullable=False))
    op.create_index('ix_known_planets_id', 'known_planets', ['id'], unique=False)
    op.alter_column('known_planets', 'planet_id',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=True)
    op.alter_column('known_planets', 'user_id',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=True)
    # ### end Alembic commands ###
#

I'm confused why...oh
I think i know whats going on.

#

let me confirm

paper flower
#

You had id column as primary key before?

unkempt drift
#

yeah i got rid of it but i dont think thats it

paper flower
#

alembic may not be the best with detecting these types of changes

#

I think you can make a pk yourself

#

(in a separate migration)

unkempt drift
#

look at the date it was created.

#

today, but shortly after 12...AM, not PM.
Essentially I was neglecting to actually create the migrations.

paper flower
#

alembic upgrade head pithink

unkempt drift
#

nevermind, still doesn't work.

paper flower
#

I don't see primary key created anywhere in the migration you've sent, I'd make one myself in a seprate migration

unkempt drift
#

That migration I sent was not relevant

#

I had never created a migration

paper flower
#

Probably like this:

def upgrade() -> None:
    op.create_primary_key("pk_known_planets", "known_planets", ["user_id", "planet_id"])



def downgrade() -> None:
    op.drop_constraint("pk_known_planets", "known_planets")
#

If you run alembic revision it should create a new empty migration

unkempt drift
#

I mean I can create a migration manually if I have to but I'd rather models.py be accurate

#

Alright, creating a brand new table entirely, let's see if alembic actually creates a migration for this...

#

@paper flower

class KnownPlanets2(Base):
    __tablename__ = "known_planets2"
    user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
    planet_id = Column(Integer, ForeignKey("planets.id"), primary_key=True)
    random = Column(Integer, default=6)
    __table_args__ = (
        #TODO: a primary key for two columns doesn't work
        #PrimaryKeyConstraint("user_id", "planet_id", name="pk_known_planets"),
        PrimaryKeyConstraint("user_id", "planet_id"),
        {"mysql_collate": "utf8mb4_unicode_ci"},
    )

creates

"""create test known_planets2

Revision ID: 6bbe319e7f99
Revises: 4e7c01db8a2a
Create Date: 2025-01-18 13:10:57.305330

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '6bbe319e7f99'
down_revision: Union[str, None] = '4e7c01db8a2a'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('known_planets2',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('planet_id', sa.Integer(), nullable=False),
    sa.Column('random', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['planet_id'], ['planets.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('user_id', 'planet_id'),
    mysql_collate='utf8mb4_unicode_ci'
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('known_planets2')
    # ### end Alembic commands ###
paper flower
#

Seems correct

#

But you already have an existing table and have to kind of not delete it 😅

unkempt drift
#

I didn't delete a table

#

Also does it seem correct? ther's no reference to primary keys in the upgrade() section

paper flower
#

There is sa.PrimaryKeyConstraint('user_id', 'planet_id')

unkempt drift
#

Oh. Sorry, my eyes have been staring at my terminal so long that they're losing their effectiveness.

#

Yeah, this is bizarre. for the actual real table it seems to be refusing to change it to a composite key.

#

Is there a way of forcing that?
note that there is no data I care about...in fact I am completely destroying the database and creating a new one from scratch each time.

#

I could create subsequent migratiosn that drop the table then recreate it?

paper flower
#

Alembic doesn't seem to support autogenerating/altering primary keys right now, just write a migration for it I think 🤔

paper flower
#

If you're just developing it's fine to just remove all the migrations, drop the db and make new one + migrations

unkempt drift
#

what else would i be doing but just developing?

#

I'm not maintaining a production database if that's what you mean

paper flower
#

dropping production database ok_handbutflipped

unkempt drift
#

well, thanks

#

I am so confused by migrations.
I had aniother question here on new years even about all of this, and you had actually answered me.
This was my solution lol:

#!/bin/bash
DB_ADDRESS=127.0.0.1:3307
export DB_ADDRESS

set -e  # Exit immediately if a command exits with a non-zero status

MIGRATION_MSG=${1:-"default migration message"}

# Stop and remove any existing container
docker stop dev_db || true
docker rm dev_db || true

# Start a fresh database container
docker run --name dev_db \
  -e MYSQL_ROOT_PASSWORD=password \
  -e MYSQL_DATABASE=game \
  -e MYSQL_USER=user \
  -e MYSQL_PASSWORD=password \
  -p 3307:3306 \
  -d mariadb:10.5

# Wait for the database to initialize
echo "Waiting for the database to initialize..."
sleep 10
#until docker exec dev_db mysqladmin ping -h localhost --silent; do
#  sleep 1
#done
echo "Database is ready!"

#rm -rf alembic/versions/*

# Ensure Alembic is synced to the current state
alembic stamp base
alembic upgrade head

# Generate a new migration based on models
alembic revision --autogenerate -m "$MIGRATION_MSG"

# Apply the migration
alembic upgrade head

docker stop dev_db || true
docker rm dev_db || true
#

chatgpt did help me but it took a LOT of arguing because AI is terrible and forgets everything after you told it.
The alembic stamping stuff makes no sense to me

west hill
#

its kind of similar to git
alembic stamp: moves the head/pointer to a particular revision/migration. It uses this to know where to start the migrations from

alembic upgrade; Applies those changes

also u might prolly wanna migrate the data too alembic is only schema migration afaik

unkempt drift
#

thank you

cyan dirge
#

Hey guys, does somebody know if I can visualise results of sql queries in qgis?

trim pasture
cyan dirge
#

it seems that there is an option but it doesnt work

#

I choose add layer and its doesnt add it

hushed smelt
#

Hey everyone

#

I am trying to create a datacube

#

With like time lat lon and around 9-10variables values at that particular time

#

Which db handles Multidimensional data pretty well?

#

I read about scidb

#

Dimension of data will be like this lets say time = t lat = (200,200) lon = (200,200) and all the variables will be of (200,200)

#

Currently I tried creating a cube in hdf file

#

By appending each data to it sequentially and mapping to that particular time and I am able to query it as well for olap operations

#

On my system hdf files are working great

#

But I belive if we upload it to server and multiple user query it

#

Then it will not be the best choice right?

hushed smelt
#

Or should I try to create my own rdbms?

#

Found something good

#

Postgresql with times Caledonia and postgis

mental quarry
#

Hi to all

lament sandal
#

anyone knows how to get rid of this error in sqlalchemy.
sqlalchemy.exc.InvalidRequestError: Object '<User at 0x7f9df97cb710>' is already attached to session '12' (this is '13')

#

I tried clearing database removed cookies close and run the server but this still remains the issue.

scarlet zephyr
paper flower
#

That's not a good fix imo? Just don't use multiple sessions in one context without a need for that.

violet cove
novel crest
#

?

paper flower
hasty ore
#

Goodmorning could someone tell me what the difference between the two queries pictured. The query at the top is mine and I’m retuning a 0 value . I’m not sure what I’m missing …

west hill
#

i am assuming they have a column with the elaborate name Elementary, Middle... which is signified using backticks to account for space and commas in the name

#

meanwhile you just use single quotes which makes it a string

spare fox
#

How can I download data automatically everyday from website (only specific entries) and connect it to database?

I tried website scraping, API, but I think it's not efficient due to website policies

delicate fieldBOT
#

5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.

wise goblet
#

if they don't allow downloading their data programmatically, then downloading it would be against their Terms of Services

#

Ask their administrators for efficient way to load. They are supposed to be providing API if they are willing to share it

spare fox
#

Thank you. Can you do it with Download Station.

potent plover
#

Wrote this up yesterday. I've fallen down enough pits over the years connecting to and querying databases in higher-volume applications that I wrote a howto on connecting and using an RDS-style db (with a read replica) with FastAPI, SQLAlchemy, and asyncpg. https://tableroq.substack.com/p/production-python-1-setting-up-fastapi No paywall. I consider good database connections a community service 😛

cosmic obsidian
#

Hey everyone, I need some help with my logic in Node.js and Mongoose. The issue is that when I create a coinflip and the logic removes the items, the items are removed once the session comits (this lets the items still be in the inventory for somewhile), which works fine. However, if I try to create a second flip while the first one is still being processed (using the same items), I get this error:

errmsg: 'Caused by :: Write conflict during plan execution and yielding is disabled. :: Please retry your operation or multi-document transaction.'

Like it doesn't let me use the items twice which is also fine but is this error something to worry about? and i also don't like how it returns an internal server error then it should be more a "you cannot use those items" (this all while the first flip is creating)

delicate fieldBOT
#

:incoming_envelope: :ok_hand: applied timeout to @honest cairn until <t:1737928549:f> (10 minutes) (reason: duplicates spam - sent 4 duplicate messages).

The <@&831776746206265384> have been alerted for review.

pearl lodge
#

how do i insert an empty stuff inside a foreign key?

#

like, no value

#

i have 1 database column and i want to insert empty value there

fiery crescent
nova hawk
#

You can have null if your foreign key column is nullable

pearl lodge
#

the 4 foreign keys?

nova hawk
#

No

#

Is there a reason to hardcode 3 soulmates instead of making it dynamic?

pearl lodge
#

and also i have little knowledge about sqlite

#

i only know the basic of the basic

nova hawk
#

You could have a member_soulmate table to allow for any number of soulmates

#
CREATE TABLE IF NOT EXISTS member_soulmate (
  member_id INT,
  soulmate_id INT,
  PRIMARY KEY (member_id, soulmate_id),
  FOREIGN KEY (member_id) REFERENCES artist(member_id),
  FOREIGN KEY (soulmate_id) REFERENCES artist(member_id)
)```
#

You can then query all the soulmates of the member_id without being stuck on having a certain number @pearl lodge

pearl lodge
#

like there is the person, the soul mates and finally the lover

nova hawk
#

member_id to lover would be a seperate table from member_id to soulmate

#

These tables linking 2 things togheter are often called associative tables or junction tables

#

They are used to represent many to many relationships like these

pearl lodge
#

i see, two tables, even thought sounds unescessary creating two more, but since you are more experienced than me you know something i don't know

#

my plan it's to be 3 soul mates and 1 lover for each member,

#

but i can see the thing you do

nova hawk
#

If it's always going to be a static number you can have it in one table

pearl lodge
nova hawk
#

It would allow you to enter any number of soulmates, from 0 to infinity

pulsar marten
#

Hey all.
Anyone have any suggestions for a solution to the following.
I have a an Airflow instance on premise that is being asked to sync data between on premise MSSQL and Azure SQL server.
It is almost entirely ELT, with little/no transformations happening. Mostly we follow a pattern of water marking the tables or truncate and load.
Our solution is very complicated and relies on checking set differentials between pyodbc row objects and I want to get away from this.

I have explained to management that we should not be loading the data into memory (Airflow is not a compute engine) but it has largely been ignored/not prioritized.
Is there a built in package or library/tool that can handle this?
The main issue is we are forbidden from having azure simply pull in the changes via cdc or azure data factory due to security reasons.
I think the easiest path is have airflow call SSIS jobs from the on premise servers, but was curious if there is another way.

Thanks

brazen charm
pulsar marten
brazen charm
#

I can't say, we're AWS infra, haven't work enough with Azure to say

pulsar marten
#

Fair enough. Appreciate the time.

radiant estuary
#

Currently using MongoDB to store products, their information and historical data for each product. the historical data starts getting bigger and even with a reasonable amount of indexes, query times are going up.

Should I move the historical data to a different collection since they are less frequently requested? or would sharding be the right approach?

amber owl
#

You have several solutions, maybe moving to a more friendly time-series database is the most difficult but sanest choice. Having hot-data collections means that you'd need to constantly re-evaluate what is hot and what is not, an execute accordingly. Sharding can also help you, even though it's not the easiest thing in MongoDB.

#

I don't know your data use case but MongoDB overall struggles to scale at some point, and sometimes their solution is to throw more machine ($$$) to the problem @radiant estuary

sweet vector
#

working on building an app for pantry management, recipe management, and shopping list management. would I be best off with SQLite, Mongo, DuckDB, or something else entirely? I have very limited experience with Oracle SQL and Mongo.

thorny anchor
#

just go with SQLite to start

sweet vector
#

I do intend to include a paid feature later down the line where I can do price tracking and/or ai-generated recipes "using what you have"

#

I may mention at this point I'm also doing this as an exercise in learning prisma, I understand there's a python library for that?

#

!pip prisma

delicate fieldBOT
#

Prisma Client Python is an auto-generated and fully type-safe database client

Released on <t:1723776843:D>.

sweet vector
#

or would I be better off just using typescript since that's what it's designed for?

thorny anchor
#

I don't know

radiant estuary
amber owl
#

I'm biased in many fronts, I think non relational databases are not a very good model. So I would personally not recommend noSQL, even though some folks out there solve cool problems with them (while also spending quite some $$)

proven ridge
#

Might not be the right place to ask but I have an issue where pd.merge_asof doesn’t work for datetimes and my df is at 6000x24 already so I’m thinking Postgres might have the solution for me. Can someone help me understand how the timespan type works in Postgres ?

#

Since timespan is not supported within pandas

#

Is it defined by two different datetime columns ‘start’ and ‘finish’?

#

I’m very green to using databases almost always use df exclusively

paper flower
mellow slate
#

can someone help me its easy one

#

create table Student( SID char(4), Name varchar(20), RN int, Batch char(4) );insert into Student values ('S001','kristal',1,'2081'), ('S002','Anish',2,'2082'), ('S003','Radhesh',3,'2083'), ('S004','Dipesh',4,'2084'), ('S005','Pradip',5,'2085'); ALTER TABLE Student ADD CONSTRAINT PK_student PRIMARY KEY (SID);

#

why i am getting error while making primary key

#

other works fine

paper flower
thorny orchid
#

is there a way to have a share auto increment id between 2 tables, so that 2 rows in each table will never have same id? sqlite

#

assume im never gonna manually insert an id

amber owl
thorny orchid
amber owl
#

uuid4 for example

#

if you need to sort, you can sort by an extra created_at, or use an ULID which is lexicographically sortable

#

your two tables will most likely never collision, for example at CrateDB; as it is distributed, uuid are often used as ids, also generated columns with timestamps

thorny orchid
thorny orchid
# thorny anchor why?

its because the tables that need to share an id are very differnt to each other, sure i can make it work by combing the tables into one, such as making certain fields as another table, or making it nullable. but its just alot of work just because i need the ids to never share

tranquil aspen
#

I think talking about the bigger picture of what you need to accomplish is what is being asked of you

#

This is feeling like a XY problem

thorny orchid
#

anyways i came up with a shitty solution
i made a table,

        db.execute("""CREATE TABLE IF NOT EXISTS shared_ids (id INTEGER)""")
        db.execute("""INSERT INTO shared_ids SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM shared_ids)""")

then to get an id

UPDATE shared_ids SET id = id + 1 RETURNING id
paper flower
finite cobalt
#

Is the psycopg2 library the best option? it's just the first one i found and already implemented into my project and i don't know if it's worth it to search for other ones.

tepid basalt
#

Yes, psycopg is fantastic. You likely want psycopg. It's version 3 of the same library. Shouldn't take much to migrate to it.

bronze fulcrum
#

Guys, want to ask, if anyone use SQLAlchemy, how to limit the number of records?

#

Like this SQL:
SELECT * FROM Users LIMIT 3 OFFSET 1

#

Also how to offset

finite cobalt
tepid basalt
median hinge
#

Can someone explain why

sql = """
    INSERT INTO mathProblemSolver_mathproblemsolve (imageLink, answer, answerPlainText, user_id, status) 
    VALUES (%s, %s, %s, %s, %s)
"""

data = (self.imageLink, self.answer_uuid, self.answerPlainText, self.userID, 1)
cursor.execute(sql, data)

can avoid skibidi kid run sql injection rather than

sql = f"""
        INSERT INTO mathProblemSolver_mathproblemsolve (imageLink, answer, answerPlainText, user_id, status) VALUES 
        ('{self.imageLink}', '{self.answer_uuid}', '{self.answerPlainText}', '{self.userID}', 1)
    """
    
cursor.execute(sql)

#

ChatGPT answer doesn't make sence for mehttps://chatgpt.com/share/67a0e6b1-e9a4-8009-92bc-6d4ec26aeb09

indigo rose
#

!user

delicate fieldBOT
#

You are not allowed to use that command here. Please use the #bot-commands channel instead.

tepid basalt
# median hinge Can someone explain why ``` sql = """ INSERT INTO mathProblemSolver_mathpro...
  • Don’t manually merge values to a query: hackers from a foreign country will break into your computer and steal not only your disks, but also your cds, leaving you only with the three most embarrassing records you ever bought. On cassette tapes.

  • If you use the % operator [or f-string] to merge values to a query, con artists will seduce your cat, who will run away taking your credit card and your sunglasses with them.

  • If you use + to merge a textual value to a string, bad guys in balaclava will find their way to your fridge, drink all your beer, and leave your toilet seat up and your toilet paper in the wrong orientation.

tepid basalt
median hinge
tepid basalt
#

Because the adapter converts the types from Python to SQL, instead of sending them to the database as strings.

#

Some adapters, like psycopg, even send the variables separately so they're never evaluated as SQL.

median hinge
#

at least the con artists wont steal my credit card

scenic dirge
rare fox
#

Help pls

eternal jacinth
#

Hi, I'm getting some error. Here is my code:

def get_code_verifier(discord_id):
    data = redis_client.get(discord_id)
    if data:
        data_dict = json.loads(data) # Error underlines "data"
        return data_dict.get('code_verifier')
    else:
        return None
```Error:

Pyright: Argument of type "ResponseT" cannot be assigned to parameter "s" of type "str | bytes | bytearray" in function "loads"
  Type "ResponseT" is not assignable to type "str | bytes | bytearray"
    Type "Awaitable[Any]" is not assignable to type "str | bytes | bytearray"
      "Awaitable[Any]" is not assignable to "str"
      "Awaitable[Any]" is not assignable to "bytes"
      "Awaitable[Any]" is not assignable to "bytearray"

Libraries: Redis Cache
hushed smelt
#

Has anyone used postgresql with postgis and timescaledb for rastor data?

#

Really need some help on how to transfer my data in hdf files to postgresql

pseudo robin
#

What happened with mnist???

deft apex
#

hey guys, just was wondering, how useful/necessary are databases for machine learning? specifically computer vision

#

if im correct, pandas is centered around databases (or is it just data frames that i'm confusing databases with) so would that be enough or would sql/some dbms also be helpful to have under my belt

deft apex
#

also what are some pros and cons of each of the 4 dbms types (network, hierarchical, relational, and oop), asking cause i want to know which type is best for me to learn

storm mauve
storm mauve
storm mauve
# deft apex if im correct, pandas is centered around databases (or is it just data frames th...

DataFrames != Databases
data frames are just a form of representing data, a little similar to spreadsheets

If you want to touch anything related to data, it's fundamental to have a basic understanding of SQL
Being familiar with the pandas API is also a good idea if you plan to work with data in Python, some other libraries straight way copy their API too. Start with the pandas official User Guide

deft apex
#

also which relational dbms is it best to go with, or does it not matter

#

currently i'm learning tsql

deft apex
woven kelp
#

is there any idea on how to establish gateways in powerbi?

storm mauve
main widget
# woven kelp is there any idea on how to establish gateways in powerbi?

"This really depends. From what I've done so far on Power BI, I see two types of gateways: one that provides a “connection” to a file on your local PC (like an Excel spreadsheet) and the other to any database (MySQL, PostgreSQL, etc.). For the local PC, you need to download the gateway configuration onto your machine and point it to the file (the gateway config installl on Microsoft).With databases, you just need to upload a Power BI file with a connection to the database and then configure it again in the Power BI web interface (Fabric). Sorry if my English isn't perfect, but feel free to ask me any questions

icy oyster
#

hey guys, trying to change the path of the database storage for postgresql

#

has anyone done this before?

real roost
#

hi folks, can anyone recommend any beginners books that will help me build towards my goal of applying for my first job as a data analyst? i have a strong understanding of mathematics and calculus already and i am currently teaching myself python - i've just started to realise exactly how broad this field really is. ty!

rotund bison
real roost
wise goblet
#

Replace /custom/mount with desired host path

pliant hemlock
#

Does anyone know if there's a way to find the quantiles of a row of a pandas dataframe? I was given a dataframe where the rows are years, the columns are different countries and the data is population. Have to have the 10th percentile of the data of a specific year.
Unsure if this is the right chat for. This question tbh.

delicate fieldBOT
#
Not in a million years.

No documentation found for the requested symbol.

thorny anchor
#

!d pandas.DataFrame.quantile

delicate fieldBOT
#

DataFrame.quantile(q=0.5, axis=0, numeric_only=False, interpolation='linear', method='single')```
Return values at the given quantile over requested axis.
torn sphinx
#

database bros and girls, you sure ric falir won 16 championships????

deft apex
#

python bot is insane

#

!d pandas.DataFrame

#

why did the bot react with a trash can lmfao

#

!d numpy.array

delicate fieldBOT
#

numpy.array(object, dtype=None, *, copy=True, order='K', subok=False, ndmin=0, like=None)```
Create an array.
deft apex
#

oh

#

nevermind i'm stupid

#

trash can idea is insane

azure niche
#

Hello

compact crater
#

I would like to have a related (one to one) object eagerly loaded whenever I retrieve an object from the db using SQLAlchemy. For example, each User has one Role. If I do user = session.get(User, 12), I would like the role attribute to be eagerly loaded, so if I do user.role.permissions afterward, the db will not be hit.

#

I'm porting from a manual approach in another language which used:

"select " select-columns " "
"from users left outer join roles on users.role_id = roles.id "
"where users.organization_id = $1 and lower(username) = $2"
#

ChatGPT stated, "Setting lazy="joined" in relationship() means it will always be eagerly loaded by default."; however, it unsurprisingly lazily loads. Not sure why it expected "lazy" would indicate "eager".

#

Hmm... never mind, it seems to be working now - sorry for the noise!

paper flower
#

You can specify loading options on a query level:

stmt = select(User).options(joinedload(User.roles))
user = session.scalar(stmt)
# Or if you're using .get
user = session.get(User, ident=12, options=(joinedload(User.roles),))
compact crater
paper flower
#

I mostly tend to add it on individual queries, depending on a project there could be a lot of tables, keeping all of the relationships in check could be a challenge

#

Also with async lazy loading isn't a thing, so I'm forced to add a loading option somewhere 😅

compact crater
#

Sure, I expect most relationships won't be eagerly loaded like this.

paper flower
#

If you want you can add lazy="raise" to explicitly forbid making lazy queries

compact crater
#

Is it possible to do the opposite i.e. default to eager, as above, but on rare queries where I don't need the role, to turn off the eager loading in the query?

paper flower
#

I used defer and undefer that way, one of my models in a project has a very big text field 😅

#

e.g.

class TextFragment(Base):
    contents: Mapped[str | None] = mapped_column(deferred=True)


stmt = select(TextFragment).options(undefer(TextFragment.contents))
#

I think you can do the same with relationships

compact crater
#

That would be awesome.

#

Fortunately, this first app isn't very performance sensitive, so I have some time to read up on SQLAlchemy techniques.

icy oyster
#

Any help is much appreciated

hoary crest
#

Hi, i dont know if this is the coreect chat but anyone know i site to upload python code and work 24/7

deft apex
#

what's the most commonly used dbms

torn sphinx
#

I don’t understand how data frames work

gilded bluff
#

can anyone recommend a database very very similar to mongodb but its very very very fast?

weak maple
#

Ping me plz

hidden garden
#

Hi Guys I was wondering if anyone has some interesting ideas for a GUI im working on. It's an app that reconcilies data between sources. I added Radar charts, time progression, filtering capabilities but it's all in ktinter and custom tkinter

#

I wanted to make something similar to ios ui but i'm pretty new

torn sphinx
#

Where/how do you host a data base?

torn sphinx
#

Could someone shed some light on this lmao? I don’t know much about databases.

deep jetty
#

You missed the post with the community note

#

There's not much to know

  • Elon made really dumb statements that show he has no idea WTF he's talking about
  • Someone called him out for it
  • Elon retaliated against being called out by calling people slurs
#

that's pretty much it

deep jetty
torn sphinx
#

Uh

#

Ah

#

Sick

deft apex
#

which is better, mysql or postgresql

heady cove
deft apex
#

what would a good data pipeline roadmap be

#

i have a roadmap that i'm following for sql specifically but that's only a part of dbms, and dbms itself is also only a section of data pipelines

#

i'm looking into learning at least the basics of every part of data pipelines so that i have a baseline of each part, though the part i'll be specializing in is the end/data usage part, specifically machine learning, so i want to see if later on i can try to create a full data pipeline for my own ml applications

slender hawk
#

guys i already start a python project but i confused witch Database should i use MySql or PostGreSQL ?

brazen charm
#

Postgres

wise goblet
#

SQL simplified to database as a file

#

It has unit testing code 679 times more than working code

#

Quite quality one choice

brave hatch
deft apex
wise goblet
icy glacier
#

No permissions to worry about either, user setup, etc.

wise goblet
deft apex
deft apex
#

i just went with mysql cause i like that you can run individual queries instead of having the run the whole file

#

i could also switch to postgresql though

#

cause the download comes with it

wise goblet
deft apex
#

just would have to make a postgresql server

#

the free version only allows 2 sql servers and 2 nosql servers though

#

for sql that's fine, but for nosql it sucks cause then i can only try out 2 among network, hierarchy, and oop dbms types

icy glacier
icy glacier
deft apex
#

nah i don't think so

#

i'll be honest i don't even know what that means

#

i know nothing

#

still learning basic sql

#

though i could probably finish learning all of it in a day or two

deft apex
#

out of these 3 which 2 are best, mysql, postgresql, and mariadb

tranquil aspen
#

It's up to you to choose based on your own requirements. Best depends on what you need and how you need it

tough dew
#

hey anyone here have experience with qt?

coarse sandal
#

Anybody read sql for smarties? is it worth reading?

meager fable
meager fable
meager fable
#

Hi

pastel vale
#

In what ways can I make my code faster when working with databases (aside from trying to keep as much of the database part in sql)?

tranquil aspen
#

It might help to talk about what you are doing specifically, the scale of the data, and how it is consumed. Are you trying to make queries faster? Rendering? Need a lot more info

pastel vale
#

Im just talking in general. Assume Ive got a very large dataset I need analyse. What do I need to do to make queries run faster?

tranquil aspen
obsidian basin
#

I am getting the weirdest error when trying to use flask migrate. Can someone help?

flask db init works but flask db migrate -m "Initial migration." is causing the error

https://paste.pythondiscord.com/ZFCA

I also posted this in web development

wise goblet
wise goblet
#

When u connect via pgadmin, u can see active sessions with which queries they ran

#

Can i get same info via Postgres query / in a raw way with PSQL?

#

i need easier interface to find query of interest to me

#

having them all in a raw way will help me easier grabbing needed one by notepad search

#

found, at least

select pid,
       usename as username,
       datname as database_name,
       query,
       application_name,
       backend_start,
       state,
       state_change
from pg_stat_activity
deft apex
#

have any of you guys used neo4j, if so, did you use it for any ml related tasks?

glacial cave
#

I'm using MariaDB v11 and I'm trying to implement a search type functionality on the clients_test table that is defined as

clients_test (first_name TEXT, last_name TEXT, number TEXT, email TEXT)```
on the UI multiple inputs are provided (first & last name, number, email), they can fill in any field and all fields should be used to find all rows matching partial/full data. I'm not really sure on how to implement this in SQL or if there's a better way to? something I tried to do is
 ```sql
SELECT * FROM clients_test WHERE first_name LIKE "jak" AND last_name LIKE "" AND number LIKE "" AND email LIKE "";```
 AND
 ```sql
SLECT * FROM clients_test WHERE SUM(SUM(first_name LIKE "jak") + SUM(last_name LIKE "") + SUM(number LIKE "") + SUM(email LIKE "")) > 0```

all the values are parameterized with `?`, above `""` values are just examples for empty inputs. `jak` is partial for `jake` in this case.

 1st doesn't return the correct (any)  columns, i assume because some columns are empty (`""`). 2nd is syntax error but i felt maybe something like might be more plausible? not sure how to implement that properly or if there's a better / simpler / more efficient way to do this. can't find much searching online either (might be wrong search terms?). any help is appreciated!
glacial cave
#

and i just realised what was wrong with the 1st query... i didnt have % in the input hidepain
gonna leave the message in case someone suggests a better awy

deft apex
#

what are some good projects for working with databases and sql

tranquil aspen
jolly thicket
#

Has anyone here worked with dynamodb?

#

So here's my scenario

  • I need to get tasks that were created this month I have about a million tasks or more waaay more. But I want them sorted by their due date

My current approach is to have their createdDate in the SK so that I can get the ones created in this month Instantly that will shorten my dataset to about 50,000 or less then I will sort them in my application manually

Is this a good approach i can't think of any other solution 😭😭

weary pawn
#

Hi guys, could you please tell me if my approach is correct? I have a table in postgres with uuid and code and each of these columns must contain only unique entry and I wanna check by insert on conflict do nothing ( because it's concurrently safe ) that these requirements are met. So, I'm going to create unique constraint on uuid and another unique constraint on code. And when I try to insert I will get unique constraint violation error, if either one or both not unique. Sounds ok?

paper flower
# west hill why not use compound keys

I think they mentioned that they want to have uniqueness across single field too, so having two duplicate ids or codes shouldn't be valid?
Their solution sounds correct though

west hill
#

yep sounds correct also depends on whether op also wants like combinational uniqueness which is what i often finding myself in need of

paper flower
#

Combinations would be unique too

#

they'd literally have both columns under their own unique constraint, making duplicate combinations impossible

west hill
#

yes u would have like only a single instance of (x1, y1) one to one mapping compound keys can be one to many or many to many

paper flower
#

Btw, better to not make composite primary keys if you're going to refer to that table from somewhere, since you'd have to create 2 columns there, but it's a valid case if you have some kind of multitenant system, e.g. if you have customer_id on each of your tables

west hill
#

an example of how i use it might go like this
user table (userid, name email, etc)
roles (role id, name, scopes etc)

user role association (user id, role id)

paper flower
#

If you have a m2m table (association) it's fine to use composite pkeys there since it's not going to be referenced from somewhere in 90% of cases, also generally sounds like the "correct" solution on how to make one

west hill
#

true

#

i wish sql alchemy had lazy loading tho without me performing joins everywhere iirc they dont support async lazy loading when accessing these relationship properties from the model

paper flower
#

Why would you use lazy loading? 🤔

#

It's inefficient

#

also generally leads to N+1 Query problem

west hill
#

i set lazy="joined" iirc

paper flower
#

That's eager loading

west hill
#

which loads it along with the main model

#

yeah

#

sometimes i may or may not need that property depending on my endpoints along with the main model

paper flower
#

I wouldn't configure it on models, you can specify the loading you want on individual queries:

stmt = select(User).options(joinedload(User.profile), selectinload(User.posts))
west hill
#

honestly i feel like in most cases i could prolly just do without sqlalchemy, just asyncpg and writing my own queries

drowsy sedge
#

https://paste.pythondiscord.com/EAVQ

why am i getting an error message saying collecteddates/products arent defined when they clearly are

(imports and cursor and stuff are in the code just not in the snippet)

cold trail
#

hi

scenic dirge
orchid oracle
#

Hello im trying to initialise a table in my database but it keeps giving me an error when i use autoincrement anyone knwo whats going on?

coral wasp
#

And username unique isn't right either

#

Try the example from the so link, so you can see how it's supposed to look

orchid oracle
#

alright imma try that ty

digital rune
#

hey i'm doing a chatapp and i would need some recommendation here, i'm starting to need to handle the data sent by a user and then send them to another. this means that i now need to store those data somewhere, what would be the best way to store them
in a efficient/secure way
?
i come from he #python-discussion, just to say that i know nothing about that exept that it exist smthg named my SQL

maiden schooner
digital rune
#

lol

#

complexity doesn't bother me, just not a PHD

tepid basalt
digital rune
#

hm would i be capable to go to smthg better after ?

#

like not be contrained ?

digital rune
tepid basalt
#

Yep, you could always migrate later if you needed too. (you probably won't need too)

tepid basalt
digital rune
#

if i'm stuck i suppose ill come here ask instead of discussion now

drowsy sedge
#

Is there anyway I can get a specific data from a db for a specific person

(For example my login database has the username and password)
(And the detail database has the email, credit card etc)
I want it to get the credit card of a certain username/person however I don’t know how to get it to know which user is using the tkinter app/I can’t really get if by using a unique identifier (username) as it’s in a different database

I have username as a foreign key in the database but confused if that would help my situation

I’m using python, tkinter, sqlite3

tepid basalt
drowsy sedge
tepid basalt
#

What information do you have on the currently logged in user? Use that to get the id.

unreal pumice
#

Anyone here use sqlalchemy? I'm loving it

#

First ORM I've used

#

Any other good ORMs for python?

tepid thicket
tepid thicket
tepid basalt
unreal pumice