#databases

1 messages · Page 146 of 1

glossy flume
#

ty, it worked

raw saffron
#

my condolences for using db2

glossy flume
#

lol

dark ruin
#

k

prisma flame
#

index.html

#

app is my home page i.e. index.html

#

and I want to add another page by connecting a link from home page

#

But I'm stuck I don't know how to add it?

#
  1. How to add two diiffn links at the same page
#

2.If I add new link then how do I connect to forms.html

bitter bone
jade arch
#

Hello so I've an issue
My Discord Bot is on Heroku, so my files are on my Github
But, when I try to wrote a data for saving it, it didn't save it because he has to be commiting by someone
So how can make the bot editing a file on my Github and save it ?

#

For example somone has an amount of money
I've a .txt file with every saved current money for all users. (like a file with an id by user) So I use the open method of Python (like reading and wrote/create). The Bot since he's on Heroku can actually read and write, but if it's not saved on Github, it'll read the not edited version of the file

slender atlas
#

With Heroku you just copy all of the files and run whatever, that is why it does not edit the files on GitHub (it simply copied the files from there). I don't think GitHub allows you to do that automatically.

jade arch
#

Oh ok

#

I guess it's not a very big issue, but when the bot will restart or want to create a new file, it's not saving that

#

So yeah that's a king disturbing ^^'

bitter bone
#

I don't think heroku supports something like that, personally I haven't used it so no idea.

You can try Linode or digital ocean

green raptor
#

hey, how do i create a table in sqlite with python? I need some help, couldnt find good solution online

my table:

CREATE TABLE "test" ( "Message-ID" TEXT UNIQUE, "Emoji" TEXT UNIQUE, "Role" TEXT UNIQUE )

my current code:

async def create_serverroles_table(): sql.execute("CREATE TABLE "test" ("Message-ID" TEXT UNIQUE, "Emoji" INTEGER UNIQUE, Role" TEXT UNIQUE);") conn.commit()

burnt turret
jade arch
#

Oh I didn't know about the Heroku Postgress
I'll try to get more information about that

torn sphinx
#

Hey, is this the right way to setup a MySQL search query:

      host = "my_host_ip_was_pasted_here"
      user = "my_username_was_pasted_here"
      password = "my_password_was_put_here"
      database = "personal_stats"
#

Anyone know why this won't work? I have the variables defined in the .env file and it connects to the database. My HWID is also in the db

import subprocess, requests, time, os, pymongo
from dotenv import load_dotenv
load_dotenv()

hwid = subprocess.check_output('wmic csproduct get uuid').decode().split('\n')[1].strip()
mongo = pymongo.MongoClient(os.environ["MONGO_DB_URL"].replace("<password>", os.environ["MONGO_DB_PASSWORD"]))
db = mongo.get_database("hwid").get_collection("HwidKeys")


def HwidKeys(ctx):
    return db.find_one({"hwid"})

try:
    if hwid in db:
        pass
    else:
        print('[ERROR] HWID Not in database')
        print(f'HWID: {hwid}') 
        time.sleep(5)
        os._exit()
except:
    print('[ERROR] Failed to connect to database')
    time.sleep(5) 
    os._exit() 
    
print("Welcome, we've found you in our database!")
input()
green raptor
# green raptor hey, how do i create a table in sqlite with python? I need some help, couldnt fi...

i tried this, can someone help me:

async def create_serverroles_table(serverid): serverid = str(serverid) sql.execute(f"""CREATE TABLE {serverid} ( first text, last text, te text )""") conn.commit()

error:
`Ignoring exception in command lol:
Traceback (most recent call last):
File "C:\Users\Jakob\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "W:\Pybot\QCommunity\bot2.py", line 118, in lol
await create_serverroles_table(we)
File "W:\Pybot\QCommunity\bot2.py", line 27, in create_serverroles_table
sql.execute(f"""CREATE TABLE {serverid} (
sqlite3.OperationalError: near "823228011477860352": syntax error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\Jakob\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Jakob\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Jakob\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: near "823228011477860352": syntax error
`

torn sphinx
#

how to find duplicates in pymongo

calm prawn
#

How do I input a tuple in a sqlite3 database

#

and also dictionaries into the tuple

spring lichen
#

Just a simple question

#

What is a database

copper cedar
#

A database is a place you can store and access data

rain plank
upper hornet
#

code

def delete_data():
    # '''This function will delete data from database '''
    con = mysql.connector.connect(host="localhost", user="root", password="private@12345", database="project")
    cur = con.cursor()
    cur.execute("delete from student where rollno = %s", Roll_no.get())
    con.commit()
    fetch_data()
    con.close()

error:-

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\GoLu\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1884, in __call__
    return self.func(*args)
  File "E:\discord\discord py\db\main.py", line 166, in delete_data
    cur.execute("delete from student where rollno = %s", Roll_no.get())
  File "C:\Users\GoLu\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\cursor.py", line 568, in execute
    self._handle_result(self._connection.cmd_query(stmt))
  File "C:\Users\GoLu\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\connection.py", line 686, in cmd_query
    result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
  File "C:\Users\GoLu\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\connection.py", line 573, in _handle_result
    raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1

what is the problem?

green raptor
rain plank
#

You shouldn't have a table per server, you should have one table, maybe called guilds, with columns like guild_id, first, last and te

#

guild_id should probably be a primary key

burnt turret
#

Nah, that wouldn't allow multiple rows for the same guild

green raptor
#

@rain plank

serverid = "ReactRole-Server-" + str(ctx.guild.id)

async def create_serverroles_table(serverid): serverid = str(serverid) sql.execute("CREATE TABLE " + serverid + "(Message-ID text, Emoji text, Role text)") conn.commit()

error:

`Ignoring exception in command lol:
Traceback (most recent call last):
File "C:\Users\Jakob\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "W:\Pybot\QCommunity\bot2.py", line 114, in lol
await create_serverroles_table(we)
File "W:\Pybot\QCommunity\bot2.py", line 27, in create_serverroles_table
sql.execute("CREATE TABLE " + serverid + "(Message-ID text, Emoji text, Role text)")
sqlite3.OperationalError: near "-": syntax error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\Jakob\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Jakob\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Jakob\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: near "-": syntax error
`

#

idk whats wrong there

rain plank
green raptor
#

Is messageid unique and cant be same on two servers?@rain plank

rain plank
#

message ids are always unique, in fact, all IDs ("snowflakes") in discord are unique. Like literal snowflakes, they are always unique

wet stump
#

Hello help me database

runic finch
#

I am trying to save information from a sqlite table to a csv. I have the db connected and configured to receive information from entry on form i made with tkinter. However, everytime I click my save to excel button instead of just appending the most recent entry to the csv file it reappends the whole table under the existing info.

brazen charm
# wet stump

PostgreSQL is automatically UTF8, this aint MySQL bloblul

wet stump
#

Pls

brazen charm
#

because it's invalid PgSQL

wet stump
#

why where that syntax error

brazen charm
#

PostgreSQL != MySQL

wet stump
#

what's wrong

brazen charm
#

your CHARACTER SET ...

wet stump
#

Ok so what to change

brazen charm
#

just delete it

green raptor
#

@rain plank ty bud i will do one table
Was stupid idea to make so many tables
Didnt know they are unique!
Thanks i learned something important today <3

wet stump
brazen charm
#

you're missing the parameters of the Datetime type

#

postgres allows several varients

wet stump
#

Which one?

brazen charm
wet stump
#

date, timestamp?

brazen charm
#

that depends on what you're doing tbh

#

read what the description of each type

#

and see which is most suited to you

wet stump
#

1999-12-02 00:00:00

#

This value

#

date timestamp?

brazen charm
#

you only choose one type

#

you can probably get away with just timestamp

runic finch
#

!close

wet stump
#

Hi help me

#

I want count months between current date and date in table

#

!open

delicate fieldBOT
#

Opening files

The built-in function open() is one of several ways to open files on your computer. It accepts many different parameters, so this tag will only go over two of them (file and mode). For more extensive documentation on all these parameters, consult the official documentation. The object returned from this function is a file object or stream, for which the full documentation can be found here.

See also:
!tags with for information on context managers
!tags pathlib for an alternative way of opening files
!tags seek for information on changing your position in a file

The file parameter

This should be a path-like object denoting the name or path (absolute or relative) to the file you want to open.

An absolute path is the full path from your root directory to the file you want to open. Generally this is the option you should choose so it doesn't matter what directory you're in when you execute your module.

See !tags relative-path for more information on relative paths.

The mode parameter

This is an optional string that specifies the mode in which the file should be opened. There's not enough room to discuss them all, but listed below are some of the more confusing modes.

'r+' Opens for reading and writing (file must already exist)
'w+' Opens for reading and writing and truncates (can create files)
'x' Creates file and opens for writing (file must not already exist)
'x+' Creates file and opens for reading and writing (file must not already exist)
'a+' Opens file for reading and writing at end of file (can create files)

proven arrow
golden warren
#

Hello their, i use sqlalchemy for my db but i have a problem, when i'm connecting on my flask page, it save my data but it say that: duplicate key value violates unique constraint "users_pkey"

I would like to check it but it doesn't work... Can you help me?

    # TODO: Rework as scheduler
    def db_updater(self):
        for u in self.s.query(Users).all():
            self.s.merge(
                Users(discriminator=u[0], email=u[1],
                      id=u[2], name=u[3], verified=u[4])
            )
#

When i run my code it return that: TypeError: 'Users' object is not subscriptable
Can someone help me?

prisma girder
golden warren
prisma girder
#

You should check it because it could be a reason pithink

golden warren
#

How can i do that?

prisma girder
#

I have single file database.py with all tables definitions and mappings

#

I don't know your project

golden warren
#

I have a single file too @prisma girder

prisma girder
golden warren
#

Hum sorry what's declarative mappings?

prisma girder
#

Can you show whole error output (with backtrace)?

golden warren
#

My model:

Base = declarative_base()


class Users(Base):
    __tablename__ = 'users'

    discriminator = Column(String(250), nullable=False, unique=True)
    email = Column(String(250), nullable=False, unique=True)
    id = Column(BigInteger, primary_key=True)
    name = Column(String(250), nullable=False, unique=True)
    role = Column(SmallInteger, default=USER.USER)
    status = Column(SmallInteger, default=USER.NEW)
    verified = Column(Boolean, default=False, nullable=False)
prisma girder
delicate fieldBOT
#

Hey @golden warren!

Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:

• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)

• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:

https://paste.pythondiscord.com

golden warren
#

Lol

#

Oh no ...

prisma girder
#

Do you have Base.metadata.create_all(engine)?

prisma girder
#

Hmm, hard to say what is going on pithink

golden warren
prisma girder
golden warren
prisma girder
#

Strange

glossy flume
#

Can anyone explain how this went wrong?

#

'Safety_Icon' is clearly a column name

bright hound
#

Since it's breaking at the first one after your original select argument I'd say it's just a syntax error

#

Try a line break after "SELECT"

#

@glossy flume

glossy flume
bright hound
#

Right because it's on the same line

#

make 'SELECT' on its own line and put all the columns and aliases in one big block

bright hound
#

weird

#

what's the data type of saftey_icon?

#

idk why that would matter but it might

#

I'm really just guessing

#

lol

glossy flume
bright hound
#

My hunch is that it has something to do with that block of arguments rather than with 'safety_icon' itself

#

Try putting a different argument as the second one in the list

#

or try putting safety_icon first

glossy flume
#

same errors 😢

bright hound
#

weird

#

Delete the table

#

jk

glossy flume
glossy flume
bright hound
#

lemme see what you did

glossy flume
bright hound
#

What does it say when you click 'learn more about this error'?

bright hound
#

you're sure that column didn't get removed from your database somehow?

#

lol

#

Can you refresh the view and it's still there?

bright hound
#

it's all in one table?

glossy flume
#

yea, would you like me to send you the csv file?

bright hound
#

no, I'm really not sure how to fix it I'm just troubleshooting based on what it says in the docs you linked

bright hound
#

why doesn't the first one need it?

thick bolt
#

I'm making a bot using discord.py. I need to store the same few attributes of data for a few hundred people, and I'm also going to be creating a web portal (Django) that will be used to manually modify entries in the database

#

Should I use JSON for this, or MongoDB?

#

Or, something better than either of those, if applicable

meager vine
#

Things might have changed, but when I last used Django I don't think it had the greatest MongoDB support

thick bolt
#

Yeah, about that

#

Should I be worried about how the database is updated?

#

What happens if the bot tries to update the database at the same time as a user on the web portal

meager vine
#

That's what transactions are for

thick bolt
#

I know very little about web development

#

I found the Django documentation for transactions though

#

Thanks

meager vine
#

That's more of a database thing than a web-dev thing

distant kayak
#
data1 = collection.find({},{"discordId":user_data['id'],"guilds":[{'id':guild_id, "owner"}]})
#

how can i know the "owner" information without define it?

lusty linden
#

how to filter date

candid fjord
#

I want to get all the table names that contain a specific column. I want to check the value of that specific column too. How do i do this?

db = sqlite3.connect('databases/tags.db')
c = db.cursor()
        
c.execute(f"SELECT * FROM sqlite_master WHERE column = {column_name}")
data = c.fetchall()

This is what I've come up so far and yes it doesn't work. How do I get the table names and the column values?

upper hornet
#

How can I check my mysql database table is empty?

bitter bone
#

SELECT EXISTS (SELECT 1 FROM table); EXISTS returns 1 if the subquery returns any rows, otherwise 0

buoyant marsh
#

Hi. Can aiopg also handle mariadb / mysql?

meager vine
#

In SQLAlchemy if I have a self-referential table like:

class TreeNode(Base):

    __tablename__ = 'tree'

    id = Column(Integer, primary_key=True)
    parent_id = Column(Integer, ForeignKey('tree.id'))
    name = Column(String(50), nullable=False)

    children = relationship(
        'TreeNode', cascade="all",
        backref=backref("parent", remote_side='TreeNode.id')
    ) 

Is there a nice way to get the full tree of a given TreeNode? Or perhaps depth information?
Perhaps something which would allow:

    node = session.query(TreeNode).first()
    node.full_tree()
    # returns string like name of node > name of child > name of grandchild etc etc
    node.depth()
    # returns how deep in a tree this node is
restive goblet
#
if db.execute('''SELECT link_articulo FROM articulos WHERE link_articulo = ?''', (url)) == 0:```
#

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 77 supplied.

#

sqlite is taking my parameter url (it's a string) and thinks that every char is a different binding

hexed estuary
#

I have a list of rows. I want to insert them all into a sqlite database, and, if there are rows the primary key of which is already in the database, then this row should just be ignored (the current value in the database left as-is).

This, I believe, can be done with a INSERT OR IGNORE INTO statement. But I have another requirement - I want to get back, for each row, whether that insertion succeeded. How can I do that?

whole garden
#

can somebody help me with an Entity–relationship model

proven arrow
gentle hatch
#

hello i need help in mysql

dry bloom
#

I'm sure this is common, mssql server local getting actively refused to connect. What should I also be doing? Tried like 4 different mysql modules all throw the refused it error

gentle hatch
#

i am getting error , pls help

#

why this error occurs

proven arrow
gentle hatch
#

i am new to mysql , so i dont know

proven arrow
#

If you really want to then you can escape it, but best to avoid using those kind of names .

dry bloom
#

This is on a windows box fyi

proven arrow
#

But doesn’t really matter, it’ll be same everywhere

dry bloom
#

Yes

proven arrow
#

How can you be sure?

gentle hatch
#

on mac ?

proven arrow
#

On Mac it’s with docker

dry bloom
#

I'm logged into the sql manager studio. Services show it running

proven arrow
#

Ok so are you using sql server or mySql?

#

They are two different things, in your question you mentioned both

gentle hatch
#

i am using pop os (ubuntu based ) so i installed mysql server thru the terminal

#

sudo apt install mysql-server

gentle hatch
#

@proven arrow

proven arrow
#

What?

gentle hatch
#

i installed mysql-server

proven arrow
#

I was answering question of another user, not you

gentle hatch
#

ohh ok

gentle hatch
real pivot
#

Hello

#

Which database provides maximum free memory usage among all?

tawdry grotto
#
@bot.listen()
async def on_message(message):
  liczbaa = 300
  liczba += 1
  print(liczba)
``` How to save accidents worked in replit?
harsh pulsar
#

@cosmic wave wrong channel?

harsh dew
#

how do i delete a specific id from a db with tinydb (yes laugh all you want, i only need to store maximum 5 numbers per id, unless you have a better one for me to use)
current db looks like {"_default": {"1": {"id": "781", "walksanator": "2", "test": "2", "test2": "1"}}}
and i want to remove the ['_default']['1']

#

well since all the information is test/dummy data
anyone got another db i could use (offline please)
that allows me to store a id and a username:choice dictionary in it

lusty grail
#

any specific reason you want to use document oriented DB rather than SQL @harsh dew ?

#

it looks like your data structure is dictionary with well defined and not nested structure, at least in the specific example you show

left scaffold
#

Hey! This is what I'm doing with a discord bot database but I can't get it to list each task which is a column name in the database. Due to there being multiple columns I can't figure out how to do it.

tasks = await self.client.db.fetchrow("SELECT task FROM todo WHERE userid = $1", ctx.author.id)

join_tasks ="\n".join([f"**{num}.** `{tasks}`" for num, taskthing in enumerate(tasks, start=1)])

I want to get every value of task from the database and put it into join_tasks basically.

harsh dew
lusty grail
#

so that is the reason you want to use one?

harsh dew
#

and i think it will be something like
{781:{"walksanator":"2", "test":"2","test2":"1"}}

lusty grail
#

no you can do mutiple tables

#

in SQL I mean

harsh dew
#

so just use a json db

lusty grail
#

why do you call it json DB?

#

I am speaking about SQL/RDBMS

harsh dew
#

i am using tinydb right now
which is a json db

lusty grail
#

yeah

#

but do you have a specific reason you want to use document oriented (json) DB over relational/sql?

harsh dew
#

{781:{"walksanator":"2", "test":"2","test2":"1"},{454:{"walksanator":"4", "test":"1","test":"4"}}}
that would be a example of a filled out db
so it shouldn't be hard to write my own simple db system

lusty grail
#

well, everyithng depends on your goals I think

harsh dew
#

i am baisically storing votes
because simply put it is
{voting_id:{username:vote_option,username:vote_option,username:vote_option}}

lusty grail
#

Yeah, I mean what's you end goal?
If you want to try to write your own data managemnt systems, that's cool. But if it is just a building block of a bigger app than I would opt for using SQL

bright hound
#

If I have a postgres column with the datetime data type can I insert a string like '2021-01-02' or how does the data have to be formatted?

#

My question is can I use a string

narrow juniper
# bright hound If I have a postgres column with the datetime data type can I insert a string li...

ISO 8601 Data elements and interchange formats – Information interchange – Representation of dates and times is an international standard covering the exchange of date- and time-related data. It is maintained by the Geneva-based International Organization for Standardization (ISO) and was first published in 1988 with updates in 1991, 2000, 2004 ...

#

try string, if that doesn't work import datatime

#

builtin library

bright hound
#

Yeah I imported datetime and it's giving me a string as an output that's why I was wondering

narrow juniper
#

if you print the datatime object it will output something readable, but it's not a string

bright hound
#

Ok I looked again and I'm actually casting it to a string so that I can concatenate it to another string

#

Ok sorry trying to figure this out, hoping someone has a lot of postgres experience. I'm getting a lot of time series data and the time values for each one is represented in the UNIX msec format. So I'm using datetime to convert the milliseconds to a date, and then adding the date to a string to be inserted into a postgres database

#

Is this the best way to do it or is there something I can do like just insert the msec value into the database and then postgres converts it for me?

#

I'm auto-generating a lot of tables and auto-inserting a lot of data so I was trying to just get everything correct during the insert operation

proven arrow
#

@bright hound There is a helper function to_timestamp() to which you can pass the unix timestamp, and will convert it for you when it inserts.

ashen basalt
proven arrow
hexed estuary
# proven arrow Inserting how? Executemany function?

Hmm, good question. The solution I ended up using is:

def insert_games(games: List[Game]) -> List[bool]:
    res = []
    con = sqlite3.connect(database_path)
    with con:  # transaction
        for game in games:
            exists = con.execute("SELECT game_id from games where game_id=?", (game.game_id,)).fetchone()
            if not exists:
                con.execute("insert into games(game_id, game) values (?,?)",
                            (game.game_id, game))
                res.append(True)
            else:
                res.append(False)
    con.close()
    return res
  • performing a SELECT before every INSERT to check whether the row should be inserted. I suppose what I want to know now is what the most performant solution for the same result would be.
#

(Game is a complicated nested class that via adapters and converters gets (de)serialized to and from TEXT.)

serene pivot
#

Hey, I know this query is sorta messy and doesn't work at the moment. but I have two questions. One, is there a way to inject column names without having to format the string? Two, I'm getting the error asyncpg.exceptions.DatatypeMismatchError: argument of AND must be type boolean, not type double precision Where am I going wrong?

#
                    query = """
                            INSERT INTO userstatus (user_id, last_changed)
                            VALUES ($1, (SELECT EXTRACT(epoch from NOW())))
                            ON CONFLICT (user_id)
                            DO UPDATE SET {0} = userstatus.{0} + (SELECT EXTRACT(epoch from NOW()) - userstatus.last_changed)
                            AND last_changed = (SELECT EXTRACT(epoch from NOW()))
                            WHERE userstatus.user_id = $1;
                            """.format(bstatus)
#

would it be better to just pass the current unix timestamp as a parameter? which one is faster?

pure cypress
#

You're trying to set multiple columns when there's a conflict?

serene pivot
#

about injecting however, the formatted string gives me the shivers, but I couldn't think of another way

pure cypress
#

Yeah, it needs to be a comma.

#

In my experience, they don't allow using variables as column names. I've used and seen others use string formatting

#

It's acceptable if you're taking the column names from a constant rather than from user input

serene pivot
#

Yeah the column name is preset by another function.

#

Lastly, is it faster to use the epoch from now() timestamp or just insert time.time() as a parameter?

proven arrow
# hexed estuary Hmm, good question. The solution I ended up using is: ```py def insert_games(gam...

You can avoid the extra select query and use insert or ignore, and then check the cursor.lastrowid or cursor.rowcount attributes that can tell you if it was successful or not. https://www.python.org/dev/peps/pep-0249/#cursor-attributes
However, generally for large lists the most performant is to use executemany, rather than execute in a for loop. Although in this case the attributes I mentioned before won’t be available. So you have to check manually, if those rows were inserted.

pure cypress
#

If you want to know you'd have to benchmark it.

serene pivot
#

So if the number of users go up.. then it could make a difference.

#
        if self.status_batch:
            async with self.batch_lock:
                for data in self.status_batch.items():
                    user_id = data[1]["user_id"]
                    bstatus = data[1]["bstatus"]
                    query = """
                            INSERT INTO userstatus (user_id, last_changed)
                            VALUES ($1, (SELECT EXTRACT(epoch from NOW())))
                            ON CONFLICT (user_id)
                            DO UPDATE SET {0} = userstatus.{0} + (SELECT EXTRACT(epoch from NOW()) - userstatus.last_changed),
                            last_changed = (SELECT EXTRACT(epoch from NOW()))
                            WHERE userstatus.user_id = $1;
                            """.format(bstatus)
                            
                    await self.bot.cxn.execute(
                        query,
                        user_id
                    )
                self.status_batch.clear()
#

would it be better to use an executemany statement and a generator instead of iterating through the "data"

pure cypress
#

I imagine that it would be better performance, but that's not something I've benchmarked.

proven arrow
serene pivot
proven arrow
#

What do you mean? Executemany wouldn't be called inside a loop

serene pivot
#

My bad. Got confused there for a second

serene pivot
proven arrow
#

You can define the query string wherever you like, as long as it reaches that function

#

This way Each tuple from the list of data would get passed to the query string.

serene pivot
#

right but the issue I’m having is that the query string depends on the data

#

each iteration would insert into a different column

#

depending on the data

serene pivot
proven arrow
#

Right then you can’t use that

serene pivot
#

yeah unfortunate. I suppose I could insert into all of the columns.. but insert null into specific ones? but that might make it worse

proven arrow
#

Not sure what your working on here, but null columns like that are a hint of table structure that could be better designe d

serene pivot
#

yeah good point. So here’s what I thought of to track status times. When the user changes status, I insert the time they changed and their previous status.

#

the length of time they had their previous status

#

and on first insert, I just insert the time stamp

#

and the times per status go into the 4 columns. online offline idle dnd

#

Am I missing a much better way?

#

here’s my table structure

#
+-------------+-----------------------------+----------------+-------------+
| column_name |          data_type          | column_default | is_nullable |
+-------------+-----------------------------+----------------+-------------+
|   user_id   |           bigint            |      None      |     NO      |
|   online    |            real             |       0        |     NO      |
|    idle     |            real             |       0        |     NO      |
|     dnd     |            real             |       0        |     NO      |
|    past     |            real             |      None      |     YES     |
|  startdate  | timestamp without time zone |      None      |     YES     |
+-------------+-----------------------------+----------------+-------------+
proven arrow
#

Yeah can’t read any code you send on mobile, 😃

#

But how many users does your program have, or do you expect

#

How will this data you store be used later on?

serene pivot
serene pivot
proven arrow
proven arrow
#

So then why do you have columns for each status type?

serene pivot
#

I want to show user online times while providing some details on what percentage of the online time was on which status

#

So to show that dnd was say 20 percent of the online time.

proven arrow
#

I see so each of those columns for status acts as a counter then

serene pivot
#

I haven’t made the graphs or made it pretty but this basically

serene pivot
#

all the times are in seconds

proven arrow
#

Ok then this structure you have currently seems fine.

serene pivot
#

Alrighty. So not worth trying to rewrite it so i can use executemany?

#

I mean with I use batches and inserting per iteration seems like it just defeats the whole purpose

proven arrow
#

Yeah you can still use executemany, just if nothing incremented for a status then it’ll be 0.

#

If that makes sense

serene pivot
#

yeah

#

Thanks so much for the help. Appreciate the time.

proven arrow
#

Alright good luck.

serene pivot
junior sleet
#

hello anyone know about python

narrow moth
#

Hey all, I'm wondering about the best way to integrate a database.

I want a database for my DnD game. I can use Python to generate the data and set parameters, but I don't know how to access the database in a friendly way.

I want to test myself and learn. I'd like other people to be able to use it. I'd like to showcase it in my portfolio.

I've done a bit of HTML and CSS, using Flask (or similar) could "be the front-end" although web access isn't entirely necessary for me, or I could write up something for cmd2. A GUI with tkinter is also possible, but I'm far less confident.

I'd be looking at (as an incredibly rough estimate) around 5 areas of data, each one containing 40 tables, of 30 columns each, containing 5-10k entries. 30-60 million pieces of data seems like an obscene amount, but it might not be far from what is required.

Where do I start/Is there anything I'm missing?
Would there be a best choice out of PostgreSQL, MariaDB or ArangoDB in this scenario?
Is making a front-end just a part of database creation?
Should my front-end be in one of the Python GUIs or HTML, or something else?

Thanks in advance.

torn sphinx
#

I'm trying to insert an image into a sqlite database, but I keep getting the error self.BlackHole.database.execute(query)
sqlite3.OperationalError: near "<": syntax error

Code:

grid = Image.new("RGB", (300, 300), "white")

bytes = io.BytesIO()
grid.save(bytes, "PNG")
bytes.seek(0)
query = f"INSERT INTO PlaceGrids(guild,grid) VALUES({ctx.guild.id},{bytes}) ON CONFLICT(guild) DO UPDATE SET grid = {bytes}"
self.BlackHole.database.execute(query)
rustic harness
#

hey can anyone tell me how to convert user data into csv file that saves permanently (like when i run this, the data saves in a csv but when i run it a second time the data in the csv file i got the first time disappears and in its place the data entered the second time is saved)

df = pd.DataFrame(columns=["Day", "Date", "time"])
parts = int(input("Enter the number of days:  "))

for _ in range(parts):
    ed = input("Enter the Day =  ")
    td = input("Enter the Date =  ".format(ed))
    ps = input("Enter Time =  ".format(ed))
    df1 = pd.DataFrame(data=[[ed,td,ps]],columns=["Day", "Date", "Time"])
    df = pd.concat([df,df1], axis=0)

df.index = range(len(df.index))
print (df)


data = np.genfromtxt("heatmap.csv", delimiter=",")
plt.imshow(data, cmap='hot', interpolation='nearest')
plt.show()

data = np.genfromtxt("heatmap.csv", delimiter=",", skip_header=True, usecols=range(1, 11))```
sly crow
#

mysql can not connect to the server and i have not starter password what should do

#

plz help

regal moss
#

I exported database as JSON from mysql and cannot load it to python via json.loads(...), gettin error decode. But it was EXPORTED from mysql as JSON so why mysql makes it invalid JSON?

inland imp
#

Hey, I have a MongoDB database and these vertical peaks sometimes

#

What is it?

burnt turret
#

what is that chart representing?

#

and, not enough info to guess really off of just that

inland imp
#

They show up in every chart at the same time

jade swan
#
db = cluster["test"]
collection = db["test"]

post = {"_id": 0, "name": "Pizza", "price": 50}

collection.insert_one(post)
print("Done!")

I try to run this code in MongoDB, however, the terminal stays quite for a minute then prints out this error :

pymongo.errors.ServerSelectionTimeoutError: connection closed,connection closed,connection closed, Timeout: 30s, Topology Description: <TopologyDescription id: 608ab2b89d41f05565a1d100, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('scoopy-shard-00-00.cyrmt.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>, <ServerDescription ('scoopy-shard-00-01.cyrmt.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>, <ServerDescription ('scoopy-shard-00-02.cyrmt.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>]>
#

@burnt turret are you able to help? 😄

burnt turret
#

oh right

jade swan
burnt turret
# inland imp

as I said, not enough data to guess; depends on what you're doing with the db after all

inland imp
jade swan
#

i will recreate the database

inland imp
#

Do you see this when you go in the "Network Access" tab?

jade swan
#

ah hold don i did not repalce myFirstDatabase with the database name

#

@inland imp my database name is Scoopy, right?

inland imp
#

The power of optimization uwu

inland imp
jade swan
#

okay

#

add my own data

inland imp
#

Yup

jade swan
#

my database name is ScopesTesting right?

inland imp
#

You can have multiple databases

jade swan
#

ah okay

#

but this is the current one i have right?

inland imp
#

For instance, I have three, depending on their use

jade swan
#
db = cluster["ScopesTesting"]
collection = db["Data"]

post = {"_id": 0, "name": "Pizza", "price": 50}

collection.insert_one(post)
print("Done!")

now this should be my code, right?

inland imp
#

Yup

jade swan
#

i run it and its taking some time

inland imp
#

you have cluster = MongoClient(...) I guess?

jade swan
#

yes

#

same error

inland imp
#

So that would be the right code

jade swan
#
cluster = MongoClient(
    "mongodb+srv://ScopesCodez:mypasshere@scoopy.cyrmt.mongodb.net/ScopesTesting?retryWrites=true&w=majority")
#

well, my code is all correct why am i getting the error

inland imp
#

Thought you shared the whole link at first lul

jade swan
#

lol

inland imp
#

Still that ReplicaSet thing?

jade swan
#
import pymongo
from pymongo import MongoClient

cluster = MongoClient(
    "mongodb+srv://ScopesCodez:mypassishere@scoopy.cyrmt.mongodb.net/ScopesTesting?retryWrites=true&w=majority")

db = cluster["ScopesTesting"]
collection = db["Data"]

post = {"_id": 0, "name": "Pizza", "price": 50}

collection.insert_one(post)
print("Done!")

this is my full code

#
pymongo.errors.ServerSelectionTimeoutError: connection closed,connection closed,connection closed, Timeout: 30s, Topology Description: <TopologyDescription id: 608ab4bd94329195d92749ee, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('scoopy-shard-00-00.cyrmt.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>, <ServerDescription ('scoopy-shard-00-01.cyrmt.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>, <ServerDescription ('scoopy-shard-00-02.cyrmt.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>]>

thats the error

inland imp
#

I can have a lot of different IP adresses so I allowed any IP personally

#

(Not the safest thing to do though but since idk heroku's IP...)

jade swan
#

brb

inland imp
#

Add the IP you see in my screenshot

#

It allows every IP

jade swan
#

okay

#

just a little question

#

how do i add an ip

#

@inland imp

inland imp
#

"Network Access"

#

(On the left side of the website)

jade swan
#

found it

#

i made it allow access from anywhere

#

do i delete my own ip now

inland imp
#

If you want

#

You can also keep it

jade swan
#

okay

inland imp
#

Allowing every IP would allow pp to connect to your db though

jade swan
#

alr will try now

inland imp
#

In case your db link leaks for instance

jade swan
#

no one will guess my password anyways

#

works now!

inland imp
#

Nice 👌

jade swan
#

time to learn how to READ info

inland imp
#

I learnt the basics from this then I was able to read the docs

#

MongoDB has a lot of powerfull operators

torn sphinx
burnt turret
narrow moth
hazy smelt
#

How to fix MySQL connector Error: Too many connections

inland imp
#

If your datastructure is simple, knowing the basics is enough

narrow moth
regal moss
#

I exported database as JSON from mysql and cannot load it to python via json.loads(...), gettin error decode. But it was EXPORTED from mysql as JSON so why mysql makes it invalid JSON?

indigo flare
#

just making sure, is smallint/int/bigint better for storing numbers in PostgreSQL then text even if no math is being done with them?

#

I'm storing 0-60 in smallint, and discord ids in bigint

junior sleet
#

I need sql pages to learn

south ruin
#

What's the current de-facto MongoDB library for Python?

south ruin
#

Thanks! Also saw pymongodb wasn't sure which was better 🙂

south ruin
#

Or better yet don't try it at the office where you might get fired

bright hound
#

Does anyone know how to approximate how much disk space a database would take up if it was like Ohhh, idk 120,000 tables and 8 billion rows of data with maybe 15-20 columns each?

#

Database disk space calculator ^

blissful knot
#

I am trying to setup a database schema (POstgresql with sqlalchemy) where I need two columns in one table to be foreign keyed to two columns in another table. How would I do that?

slim eagle
#

does sqlite have any ways to store values in array?

bright hound
serene pivot
#

Is using an executemany statement faster or slower than casting data as a json array and using jsonb_to_recordset to insert with an execute statement?

proven arrow
vague hazel
#

is it feasible to store image data (not the image itself) in a database and check new images against database entries to see if they are identical, similar or part of one another?

sturdy vine
#

how would i search this xlsx by the username and be able to print the fullname and phone number in the username's row?

#

so far i can search the username column:

username = [val for val in df['Username:']]
``` but i want to be able to pull and separate the information from the other column in the corresponding row
serene pivot
#

What are some reasons I get invalid character errors when trying to cast a list of dictionaries to jsonb? It said invalid character "'" but no ' character was in the dict

torn sphinx
#

file is not a database
recieving this for my .db file

#

all i have within the file is a table

#

Not sure what else im suppose to put

#

While inside the database when i try .dbinfo I recieve
unable to read header

wintry verge
#

New to sqlalchemy, figured this is a decent place to ask SA help questions?

serene pivot
#

Hey! So I have this code, ```py

import json
stuff= json.dumps(str([{"guild": "805638877762420786",
"channel": f"{ctx.channel.id}",
"author": f"{ctx.author.id}",
"prefix":"hi",
"command":"hewwo",
"failed":True}]))
await ctx.send(stuff)

query = '''INSERT INTO commands (server_id, channel_id, author_id, timestamp, prefix, command, failed)
SELECT x.guild, x.channel, x.author, x.used, x.prefix, x.command, x.failed
FROM jsonb_to_recordset(CAST($1 as jsonb)) AS
x(guild BIGINT, channel BIGINT, author BIGINT, used TIMESTAMP, prefix TEXT, command TEXT, failed BOOLEAN)'''
await bot.cxn.execute(query, stuff)```

#

but I get the error

#

cannot call jsonb_to_recordset on non-array

#

what am I doing wrong here?

warm rain
#
@tasks.loop(seconds = 5.0)
    async def tempbancheck(self):
        connection: Connection
        async with self.bot.pool.acquire() as connection:
            async with connection.transaction():
                rows = await connection.fetch('SELECT "end" FROM tempmutes')    
                if rows is not None:         
                    for row in rows:
                        if row['end'] <= datetime.utcnow():
                            id = await connection.fetchval('SELECT userid FROM tempbans WHERE "end" = $1', (row['end']) )
                            user = await self.bot.fetch_user(id)
                            guild: Guild = self.bot.get_guild(id = 812314425318440961)
                            await guild.unban(user = user, reason = 'End of ban duration.')
                            await connection.execute('DELETE FROM "tempbans" WHERE "end" = $1', (row['end']), )```
Id doesn't fetch anythhing, while the table isn't empty
#

asyncpg, postgres

delicate fieldBOT
#

Pasting large amounts of code

If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pydis.com/

After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

torn sphinx
#

the db i mean

torn sphinx
nova robin
#

Does anyone have any knowledge on salesforce and python?

steel terrace
#

hey guys, is there anyone who is good at backend database in mysql?

torn sphinx
steel terrace
#

but, unfortunately I dont know mysql, so I was looking for an aid...

#

might be helpful with someones help..

#

I have started learning mysql

torn sphinx
#

For learning SQL generally sqlbolt.com is recommended (it's pinned to the channel) I did it and went to do a project with SQLite3. You could do that too,

#

SQL is mostly the same yet, they have some syntax and technical differences between the different types

steel terrace
#

I specifically want to learn mysql..

torn sphinx
steel terrace
#

oh alright

#

can I team up with someone in this project here?

wise goblet
#

a good way to refresh knowledge even if know

torn sphinx
wise goblet
#

exactly my way

#

I had a course of MySQL in uni, but I am afraid that I forgot most of it after few years

#

and I think ORM is still not the same)

#

good way to refresh

#

I think though, that writing good ORM queries can be more rewarding in spent time to received proffit though

#

but well, for a deeper understanding, why not to learn hehe Raw SQL

wise goblet
#

Plus by storing with proper number way, you allow yourself making better SQL queries

indigo flare
#

I was doing some benchmarking and swapping text for bigint changed size from 53 -> 48mb, but made queries take a little longer (however that could just be margin of error)

#

This was a non-primary key however, I haven't tested primary key performance changes

wise goblet
indigo flare
#

Was using explain analyse

wise goblet
#

the point is in.... saving even little space could be important

#

for a big db

indigo flare
#

gonna swap to bigint anyway, just wondering why

wise goblet
#

consider to compare

#

how different benchmarks for them

#

with and without db indexes

indigo flare
#

I haven't done any indexes, just have a primary key on a different bytea column

wise goblet
#

this could be important, speed of hashing can be different

indigo flare
#

lol the bytea is literally storing hashes

wise goblet
#

and indexes can take different space

#

for different formats, perhaps

#

or may be the same

indigo flare
#

Yeah, I was just doing quick testing during off time in a Computer Science lesson lol

wise goblet
#

so good SQL trainer

#

if only we had the same in university

#

it would make learning much faster

torn sphinx
indigo flare
wise goblet
wise goblet
#

like I should not do few.... requests in a row

#

when they can be combined in a bigger one

#

that does the same, without extra not needed moves

#

well, basically there are some anti pattern traps

#

which we need to avoid in ORM

torn sphinx
#

Have you learned the antipatterns by Uni is there a good resources?

wise goblet
#

so, basically no internet resources

#

only paper thin books

torn sphinx
#

Alright, no problem

wise goblet
#

after starting the course I realized

#

I need to read one more book

#

now about good pattern and bad anti patterns in SQL

#

without it my knowledge would be not complete

torn sphinx
#

Currently reading about python testing 😉 it's good

wise goblet
#

I have currently in queue 3 books about unit testing

#

hehe lol the same

#

reading really good book about unit testing

#

finally started to get it at the normal level

torn sphinx
#

Which one are you reading?

wise goblet
#

and after that I planned to read few books about my favourite framework Django

torn sphinx
#

I'm reading Python testing with pytest

wise goblet
# torn sphinx I'm reading Python testing with pytest

I am reading
Unit Testing Principles, Practices, and Patterns: Effective ...Book by Vladimir Khorikov
A really super cool one explaining which tests are good, how to write good tests, how to refactor them and making easy to support and etc

#

really big eye opener

#

it is written with examples in C#, but I don't care

#

Unit testing is universal for any language

torn sphinx
wise goblet
#

it is written with experience of author, which unit tests you should not ever write)

#

if you want to be efficient

#

and which you should

#

which bring more usefulness

#

how to score the test and to understand if it is useful for your project

torn sphinx
#

Sounds like a good book

wise goblet
#

with reading this book, plus one more.
I'll be sure that I write tests in a right way

#

uh

#
SELECT * 
FROM North_american_cities
WHERE Longitude < (
SELECT Longitude 
FROM North_american_cities
WHERE City LIKE "Chi%"
)
ORDER BY Longitude
#

than further tasks

#

then more interesting SQL queries

#

will be there 1-2 A4 lists long queries? 🤔

torn sphinx
wise goblet
#

multiple tables, and super long request through multiple tables

#

with many conditions from different tables

torn sphinx
#

there will be 2 table queries with sorting and conditions but they are not too long

wise goblet
#

you left me no room to wonder

torn sphinx
wise goblet
#

I finished

#

Hehe, one hour to complete it

#

well, I knew already SQL, I just refreshed knowledge I guess

#

ORM is still better though

#

at least if it has proper migrating system

#

much more flexibility

#

well, actually raw SQL is more flexible

#

but ORM is better in term of... moving your product between its versions

wind pagoda
#

Running an MySQL query, if I want to group by twice, do I need to use a sub query?
Example, I group a time column by minutes, and then limit 5 to get the past 5 minutes, then I want to group those 5 records into one record

regal moss
#

[Q] TinyDB | JSON:
Cannot read data from .json whom content has sometimes signs like ąół. I tried to encode as utf-8 but didnt help.

Error is: 'charmap' codec can't decode byte 0x81

wintry verge
#

I have a model called log , and on it i have a relationship defined:
user = relationship('User', primaryjoin='Log.user_id == User.id', backref='logs')
however, when I do a query like log.query.filter(item_id=id).all(), whenever I try to access Log.user.username i get a name error.
What am I misunderstanding about querying/traversing this relationship?

#

I am new to SA, so there's that.

next wigeon
#

Hey! Am new to python, and am learning how to make databases for my scripts. I want to store the db into the script's file. So am using yaml, and using the PyYAML package, how can i remove and add certain variables from the yml database file.

wintry verge
harsh pulsar
harsh pulsar
#

i recommend sqlite instead for pretty much any "light duty" app

next wigeon
#

Alright! I'll check it out, ty for the help

harsh pulsar
#

@wintry verge it would help if you showed the full code for your model, or better yet for your entire application

harsh pulsar
#

!e ```python
import json
data1 = {"thing": "ąół"}
data2 = json.loads(json.dumps(data1))
assert data1 == data2

delicate fieldBOT
#

@harsh pulsar :warning: Your eval job has completed with return code 0.

[No output]
harsh pulsar
#

that works fine ... is the encoding of your file not utf-8?

#

are you able to share the file?

#

!e ```python
import json
data = json.loads('''{"thing": "ąół"}''')
print( data )

delicate fieldBOT
#

@harsh pulsar :white_check_mark: Your eval job has completed with return code 0.

{'thing': 'ąół'}
indigo flare
#

I'm storing a sha256 hash in postgres, and have been using the BYTEA type, is there a better option? (would like to hash in app, simply store in postgres)

regal moss
#

@harsh pulsar I need tinyDB solution, try to do db.all() once you point .json db and look at error

harsh pulsar
#

i don't know anything about tinydb

regal moss
#

oh 😦

#

its kool, check it out, simple docs

#

if you want ofc

harsh pulsar
#

the problem might be tinydb itself

regal moss
#

but rly handy lightweight db

harsh pulsar
#

this does seem useful, kind of like mongo-but-sqlite

regal moss
#

anyway, thank you for solution if it was json

#

the point is I want to deply my app on githuib pages

#

and I need some db. mysql cannot be there, cos its static

harsh pulsar
#

what about sqlite? i havent had unicode issues with sqlite

regal moss
#

github pages accept onyl static*

#

yeah might be the solution as well

#

🙂

harsh pulsar
#

although, im not sure how you expect to use a database with a static site at all

#

unless you ship the database itself to the client? seems like a weird design

regal moss
#

I plan to place that json file in main directory where app.py will be, and it will read from there

wintry verge
# harsh pulsar <@!469165553337106432> it would help if you showed the full code for your model,...
    item = InventoryItem.query.get_or_404(item_id)
    history = Log.query.filter_by(object_id=item.id)\
                .filter_by(content_type_id=9)\
                .options(db.joinedload('user'))\
                .order_by(Log.id).all()
    for log in history:
        to_return.append({
            dt: log.action_time,
            user: log.user.username,
            change: log.change_message
        })

This is giving me a NameError on user not being on log inside the to_return.append()

Model:

    __tablename__ = 'admin_log'

    id = Column(Integer, primary_key=True)
    action_time = Column(DateTime, nullable=False)
    user_id = Column(ForeignKey('auth_user.id'), nullable=False, index=True)
    new_user_id = Column(Integer, nullable=True)
    content_type_id = Column(ForeignKey('content_type.id'), index=True)
    object_id = Column(String)
    object_repr = Column(String(200), nullable=False)
    action_flag = Column(SmallInteger, nullable=False)
    change_message = Column(String, nullable=False)

    content_type = relationship(ContentType', primaryjoin='Log.content_type_id == ContentType.id', backref='admin_logs')
    user = relationship('AuthUser', primaryjoin='Log.user_id == AuthUser.id', backref='user_logs')
harsh pulsar
#

i still dont understand how that will work with a static site

#

@wintry verge i don't see anything obvious but maybe someone else does

#

@regal moss my only guess regarding your original issue is that somehow the data was not written to the db correctly

woeful yoke
#

help me solve this

indigo flare
#

do a SELECT * FROM Movies and check the column name

regal moss
#

@harsh pulsar oh and btw, I would store that json db in the same directory, accessable by user, but that database only sortes Herbs and vitamis + description. not passwords etc cos website will not use login not contact forms, nothing, but loops posts from json about vitamins 🙂

brazen charm
#

it's litterally just designed to serve raw HTML and some static file assets

tranquil totem
#

why this error?```py
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "/home/runner/CaliberBot/cogs/notes.py", line 29, in note
if (await collection.count_documents({"_id": ctx.author.id}) == 0) or (await collection.find_one({"_id": ctx.author.id})["note"] is None):
TypeError: '_asyncio.Future' object is not subscriptable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: '_asyncio.Future' object is not subscriptable

pure cypress
#

You should put the await in parenthesis so it gets evaluated first: ```py
(await collection.find_one(...))["..."]

regal moss
brazen charm
#

sure, but you wont be able to change stuff

#

when it freezes it it takes a set of stuff and makes it into static files

#

so DB or not you're still essentially hard coding the values etc...

#

what it wont do is convert things like your DB etc...

regal moss
#

true but once data sotored in db, I might in future develop some website with mysql serv on side lets say, and will not have to again type data

#

or maybe I will host it on heroku, who knows

harsh pulsar
#

maybe you should consider rendering the data to a format like json

#

even if you store it in a database on your server

regal moss
#

you mean export data to json from database?

delicate rune
#

Is there an error with how I'm setting up the columns?

#
from sqlalchemy import (
    Column,
    DateTime,
    Integer,
    String,
    Table,
    ForeignKeyConstraint,
    Enum
)
from sqlalchemy.sql import func
from ..db import metadata
import enum


class PermissionsEnum(enum.Enum):
    private = 'private'
    public = 'public'


images = Table("images", metadata,
               Column("id", Integer, primary_key=True),
               Column("permissions", Enum(PermissionsEnum), default="public"),
               Column("text", String),
               Column("characteristics", String),
               Column("date_created", DateTime(
                   timezone=True), server_default=func.now()),
               ForeignKeyConstraint(['id'], ['users.id']))
#

When I went on psql and ran \+d images I only got the id column

#

I don't think my db configuration is the problem since I have another table that I can read and write to and I've seen that all the columns exist

somber isle
#

anyone know the best dbms for storing a large amount of rows into a table? Im creating a discord bot that also stores messages and I will need a lot of rows in the future

harsh pulsar
#

@somber isle "large" is probably orders of magnitude bigger than a casual discord bot will store, unless you are planning to store 100s of millions or billions of messages.

somber isle
#

well how many MB do you think lets say 1 million messages is?

harsh pulsar
#

not enough to care

#

use sqlite

#

a sqlite database is a plain file on disk that can be accessed with a python library

somber isle
#

sqlite can only handle one entry at a time though, i need an async one

harsh pulsar
#

any other database requires a separate server, trust me you dont want to go that route

somber isle
#

cause this bot will be in multiple servers

#

well ive worked with mysql server before, currently taking a dbms class rn

harsh pulsar
#

what do you mean "one entry at a time"? you can do arbitrary concurrent reads from sqlite, and writes are fast enough that you won't notice that they aren't async

somber isle
#

I was told that sqlite can only allow one write and read at a time

#

is that not true>

harsh pulsar
#

it supports highly concurrent reading

#

writing not so much, but again writes are very fast on a modern ssd

somber isle
#

ok that sounds good. using just the sqlite3 library?

harsh pulsar
#

yes

somber isle
#

or do i need to make an async version

harsh pulsar
#

i believe there is some support for truly concurrent writes too in sqlite but you might be going off-trail with that

#

also there is an asyncio sqlite library

somber isle
#

well my only concern was since the functions within discord.py are async, would the database operations needs to be async too?

harsh pulsar
#

they dont need to be async, if they are fast

#

the event loop will be blocked while the write is executing, but if it's fast you won't notice a difference

somber isle
#

ok they should be simple operations anyway just basic write and reads not a lot of hard queries

harsh pulsar
#

however if you do need to do a lot of concurrent reading, then yes you should use asyncio for that

somber isle
#

thanks smilecat

#

ive worked with sqlite3 before i just didnt know what it was capable of

harsh pulsar
#

theres definitely some reading to be done if you end up serving a lot of requests

#

but i think with aiosqlite you will be fine

somber isle
#

thanks @harsh pulsar ive actually been working on an API for sqlite3 to make it even easier to use

wise goblet
#

there is a dumb work around for Sqlite though

#

I make writing to RAM stored Sqlite and then dump it to HDD stored Sqlite from time to time ;b
makes 99% of my app time, reading from HDD Sqlite as main one

#

it is a really dirty solution, but suiting small apps

torn sphinx
#

Hi i have question

#

how to add

#

codes that generate my code

#

to database?

wise goblet
torn sphinx
#

How to change save data in txt files to save it on database

    def load_codes():
        f = open("codes.txt")
        for line in f.readlines():
            codes.append(line.strip())
        f.close()
    code_to_use = input("Podaj kod aktywacyjny:\n> ")
    def use_code():
        cmd = 'wmic csproduct get uuid'
        uuid = str(subprocess.check_output(cmd))
        pos1 = uuid.find("\\n")+2
        uuid = uuid[pos1:-15]
        uid = []
        u = open("uuids.txt", "w+")
        for line in u.readlines():
            uid.append(line.strip())
        try:
            codes.remove(code_to_use)
        except:
            print("Coś poszło nie tak, skontaktuj się z developerem programu!")
            input("Kliknij enter by zamknąć program!")
        f = open("codes.txt", "w+")
        for code in codes:
            f.write(code + "\n")
        uid.append(uuid)
        for uidn in uid:
            u.write(uidn + "\n")
        u.close()
        f.close()
        ua.close
    load_codes()
    cmd = 'wmic csproduct get uuid'
    uuid = str(subprocess.check_output(cmd))
    pos1 = uuid.find("\\n")+2
    uuid = uuid[pos1:-15]
    uid = []
    u = open("uuids.txt", "w+")
    for line in u.readlines():
        uid.append(line.strip())
    if uuid in uid:
        print("Twoje hwid jest już połączone z innym kodem! Jeżeli uważasz że jest to błąd skontaktuj się z developerem.")
        input("Naciśnij enter by zakończyć program!")
    if code_to_use in codes:
        print("Sukces!")
        use_code()
    else:
        print("Kod nieprawidłowy")```
lapis crane
#

where do i begin with sqlite?

burnt turret
lapis crane
#

thanks

wise goblet
#

It would be a good start to databases

torn sphinx
#

yeah i know

#

now

#

im

#

learning

paper flower
#

Hello, i need help with my sql query:
I want to fetch certain amount of blogs from my table, ordered by most recent post and joined with it, however with such query it would have to execute subquery for each entry in blogs table

explain analyze
select *
from blogs
         left join posts on posts.id = (
    select posts.id
    from posts
    where posts.blog_id = blogs.id
    order by created_at desc
    limit 1
)
order by posts.created_at desc
limit 5

Is there any way to achieve similar behavior with different query?

torn sphinx
#

Say you have a SQL database, you have tribe names, and the tribe has a stat, e.g. player kills, etc.
If that tribe is recurring in the database, how could you add their stats up and display the sum of all of that?

indigo flare
#

how do I do something like sql ALTER TABLE ADD CONSTRAINT whatever ON CONFLICT DO something because I have 2 tables which I want to add a foreign key to but they have possible non-present keys from one to the other

#

I have this query```sql
ALTER TABLE nicknames
ALTER COLUMN guild_id TYPE bigint USING guild_id::bigint,
ALTER COLUMN user_id TYPE bigint USING user_id::bigint,

ADD PRIMARY KEY (guild_id, user_id),

ADD CONSTRAINT fk_guild
    FOREIGN KEY       (guild_id)
    REFERENCES guilds (guild_id)
    ON DELETE CASCADE,

ADD CONSTRAINT fk_user
    FOREIGN KEY         (user_id)
    REFERENCES userinfo (user_id)
    ON DELETE CASCADE;```and the userinfo table is simply `guild_id::bigint, lang::text, blocked::bool`, so I want to just insert a default row into `userinfo` table if it doesn't already exist
near dove
#

so I use xammp for my Database and I'm trying to use import sqlite3 but I'm not sure how I would connect to the database in xammp with sqlite3

#

nvm, I'll use mysql instead :)

digital pecan
#

What is sql used for?

near dove
#

databases

torn sphinx
#

hello everyone!

blissful knot
#

I have an sql alchemy selection statement that looks like this py statement = select(email_subscriptions).where(email_subscriptions.user_id ==user, email_subscriptions.guild == guild) inside a function and I want to be able to set the table and the column names with parameters, but I don't know how to do it.

jaunty galleon
#

I need all of the guides to understand monogdb, I want to get started and use it for discord bot

#

Anyome got any good one's? I.also.need guide oj how to set up monogdb

burnt turret
#

Their docs are really nice too

jaunty galleon
#

I have a question about mongodb, it's structed by documents, which are field value. It looks really like dictionary, is it possible to convert it to that?

#

And collection stors a few of these documents

burnt turret
#

when you retrieve documents, you'll be able to use them as dictionaries yes

jaunty galleon
#

Te guide says mongodb free tier suits to small projects, but I want to use it for a discord bot, will it be ok?

burnt turret
#

more than sufficient

#

i mean, are you using their cloud based option? i don't know how much storage that gives you but it should be enough if it's a small bot

#

when i was using mongodb i was running an instance myself (not using their cloud option)

jaunty galleon
#

512 mb

burnt turret
#

should be enough i think

torn sphinx
#

which is better databse 'MySQL or MongoDB'?

wise goblet
#

because they are the best for different types of situations

torn sphinx
#

ohk

#

thanks

wise goblet
#

you can ask -> is MySql good for situation X, and MngoDB for sutiation N?

torn sphinx
#

I want a database for a discord bot(discord.js)

wise goblet
#

what do you plan to store in it?

torn sphinx
#

etc.

wise goblet
#

basically MongoDB is best to store... large arrays of dictionary like weakly structurized data.
it is very specialized to be not always possible to use it
tutorials name document type of data suiting MongoDB

SQL dbs are usually 'all around' suiting for most of tasks
efficient in their space to have data being stored in minimum available space
and then reconnected through keys with SQL queries

torn sphinx
#

ohk

#

thanks

paper flower
#

I would say that mongodb is good for non-important data? 🤔

wise goblet
#

xD, may be.

#

we thought to use mongoDB to store searching results

#

which we have no idea what to use for, except for training of neural networks later may be

#

or some other sort of post processing

paper flower
#

I wouldn't store something like user information in mongodb

wise goblet
#

perhaps user comments / news

#

something which has great amount of characters / unstructurized things

#

per one record

paper flower
wise goblet
#

well, all right

wise goblet
#

nobody stores users in MongoDB, I think

paper flower
#

I would choose postgres over mysql though 🙂

bitter bone
#

what not postgres?

#

yeah same doctor

wise goblet
#

I am actually using postgres too ;b

#

MariaDB is also an option

#

open source as well as far as I know

bitter bone
#

or json!

wise goblet
#

json is small sized alternative to MongoDB ;b

bitter bone
wise goblet
bitter bone
#

yeah, json and yml

#

both are ncie options to store configs

wise goblet
#

I mean...

#

some super cheap ass solutions offer instead of databases storing data in files ;b

wise goblet
#

JSON can be as much as a way to store data in such cases

paper flower
#

Something like sqlite would be much better than json

#

But it depends

wise goblet
#

SQLite yeah, better

paper flower
#

afaik sqlite is used a lot

wise goblet
#

I am currently using two SQLites in my project ;b

#

RAM and HDD one together

#

writing everything to RAM and dumping to HDD sqlite

#

avoiding write/read conflicts in this way

#

and twice faster to write into RAM

#

probably at a later stage will swap to Postgres

paper flower
#

Also sqlite never corrupts 😅 at least on default settings

#

And mysql is just weird

wise goblet
#

it is proprietary

#

some people afraid it would become for money only

#

that's why MaridDB appeared

paper flower
#

I would use postgres over mariadb anyway 🤔

#

I'm not very familiar with either of them but postgres is more sophisticated afaik

wise goblet
#

I used only once MariaDB, when I was asked to setup Wordpress in VPS
tutorials were for MariaDB

paper flower
#

I usually use orms so database doesn't matter that much

wise goblet
#

me too, me too

paper flower
#

But when you would have to write sql queries by hand i'd better be postgres

jaunty galleon
#

MongoDB uses JSON format?

wise goblet
jaunty galleon
#

And what is BSON?

charred arch
#
 z = await client.db.fetchval(query = "CHANNEL_ID")
    print(z)
#

code having error

bitter bone
#

yeah, BSON is what mongodb stores json as internally

charred arch
#

!rtfm asyncpg

bitter bone
#

it is binary encoding of json

kind kayak
#

hey people, im looking to create a users database that will format users like:

{
user "user1"
ukey "1234"
upass "4321"
lastlog "1/5/2021"
}

and repeat for each user, and then this form can be used to login with. the last log is also when the user was last logged in.

paper flower
#

Plus storing passwords in plain text is a no-no 🙂

jaunty galleon
#

Anyone got a guide for MongoDB with python? I already have a cluster made

kind kayak
# paper flower what is ukey?

each user has a key as part of my program. i already have the generation and storing of the variable done, i just need it to be able to be used with login

paper flower
#

What database are you using?

kind kayak
#

and how should i create a login system if passwords cant be stored in plaintext. im aware its a bad idea, i just dont know what to do about it

kind kayak
paper flower
#

I would recommend to use any realational database

#

Like postgres

#

Plus an orm of your choice

kind kayak
#

ok well i have no idea how to do anything with databases so this should be fun

wise goblet
jaunty galleon
#

Anyone got a guide for MongoDB with python? I already have a cluster made

wise goblet
# kind kayak i dont know at the moment because any tutorial i follow online just seems to bre...

!e

import hashlib

salt = 'is salt a secret key?'
print(hashlib.sha512('my secret password'.encode('utf-8') +
                     salt.encode('utf-8')).hexdigest())

print(hashlib.sha512('password'.encode('utf-8') +
                     salt.encode('utf-8')).hexdigest())

print(hashlib.sha512('my secret password'.encode('utf-8') +
                     salt.encode('utf-8')).hexdigest())


print(hashlib.sha512('my secret password'.encode('utf-8') +
                     'differrent salt'.encode('utf-8')).hexdigest())
delicate fieldBOT
#

@wise goblet :white_check_mark: Your eval job has completed with return code 0.

001 | 10df09f1ff972072e9919b0ab2413988e3d066875049d4a1dd2415a2fde29fc5f55f380b40e7d0eeb78cf055bccbdbbb1894338f49e2dc05ae48bb3d485a68e5
002 | 046ce283f3e41fc7283724db160ec234dbc497528277aade21e12d88c74965692356481c9bc772a9a24d85da2bfd644e0a4396221cfaf17f71c69a9c73495981
003 | 10df09f1ff972072e9919b0ab2413988e3d066875049d4a1dd2415a2fde29fc5f55f380b40e7d0eeb78cf055bccbdbbb1894338f49e2dc05ae48bb3d485a68e5
004 | 63916d424fd1b2f7a697e87a510f3ba10a6c9baa5cd62158d8b64e62190050d88f915ebe4dbb692a8cf7637d2be5d6532e527309aca681b41c2bc8a829cd0fea
wise goblet
#

here you go

#

as you can see first and third line were encoded with the same secret key (which is salt)

#

which allowed to encode 'my secret password' to the same hash

bitter bone
# jaunty galleon Anyone got a guide for MongoDB with python? I already have a cluster made

https://www.mongodb.com/blog/post/getting-started-with-python-and-mongodb this one
and there is one realpython one also, can't find the link for that

MongoDB

MongoDB has a native Python driver, PyMongo, and a team of Driver engineers dedicated to making the driver fit to the Python community’s needs. In this article, which is aimed at Python developers who are new to MongoDB, you will learn how to create a free hosted MongoDB database, install PyMongo, the Python Driver, connect to MongoDB and more.

jaunty galleon
#

I can't seem to find any way in pymongo to connect the cluster

wise goblet
#

all you need to store your password as hashes

wise goblet
#

and then while using the same salt

#

to check if their hashes match each other

kind kayak
wise goblet
#

keep your salt as secret

#

it is your secret_key basically

#

which should be never known

#

technically even if someone would know it

#

he would not be able to guess passwords

#

because he would have to.... check billions of combinations

#

but better be safe than sorry

#

ah and yes... don't change salt unless you wish old passwords to be useless)

kind kayak
#

yep

#

cool thanks dude

wise goblet
#

u a welcome

#

there are more secure ways to handle it though

#

I know there should exist algorithm....

#

which can encode two the same passwords 'my secret password' to different hashes

#

while being able to verify that they are still 'my secret password'

#

it will be more secure, because.... hackers would not know that two passwords are the same

#

but I guess, some hash is already better than nothing

kind kayak
#

this should be more then enough security for what i have planned thanks man

paper flower
#

There's already libraries that provide salt for you

wise goblet
paper flower
#

bcrypt uses random salt

#

argon2 too

#

So there would be no risk if you leak your salt

wise goblet
#

!e

# import the hash algorithm
from passlib.hash import pbkdf2_sha256

# generate new salt, and hash a password
hash_ = pbkdf2_sha256.hash("toomanysecrets")
print(hash_)
hash_2 = pbkdf2_sha256.hash("toomanysecrets")
print(hash_2)

# verifying the password
print(pbkdf2_sha256.verify("toomanysecrets", hash_))
print(pbkdf2_sha256.verify("toomanysecrets", hash_2))
print(pbkdf2_sha256.verify("joshua", hash_))
#

yeah, tested it

#

output

$pbkdf2-sha256$29000$JuRcy1mrVUqJcc7ZW4vRGg$rqSfPg6WOM8c4tktTB761FQ2fR2.DAvG35n.VM2YSoU
$pbkdf2-sha256$29000$itF6bw1BqPU.B8B4z3mvNQ$05O6g4YVkWvVVXJAn5M/oDTSkvdaQrPRYWZDm3kaVG4
True
True
False
#

it is exactly what I was speaking about

#

you see, they generate different hashes

#

for the same password

#

while being able to verify both of them

#

it is indeed more secure

jaunty galleon
#

I need a little help with connecting to mongo db, if I have this link format:
mongodb+srv://myusername:<password>
let's say my password is blah, should I do:
mongodb+srv://myusername:blah
or:
mongodb+srv://myusername:<blah>

paper flower
wise goblet
wise goblet
jaunty galleon
#

ah ok

paper flower
#

afaik pbkdf2 needs salt

#

passlib just generates it for you

jaunty galleon
burnt turret
#

how are you running mongodb?

paper flower
burnt turret
#

if it's on the atlas option, i'm not very sure, but you'd probably have to make user details

jaunty galleon
#

Oh yeah I just got it I think

#

one more thing

#

it says replac the test with the database

#

How can I get the database name? I know the cluster name is Sandbox

#

And what is compass

paper flower
jaunty galleon
#

Do I *need it?

paper flower
#

It depends

#

Try it and see

kind kayak
#

userJohn = {
    "user": "user1",
    "ukey": "1a2b3c4d",
    "uhash": ""
}

userSmith = {
    "user": "user2",
    "ukey": "4d3c2b1a",
    "uhash": ""
}

user = input("User Please")
chosenUser = (f'{"user"}{user}')
print(json.dumps((chosenUser)))```
#

im clearly stupid but wtf am i doing wrong

#

it says line 1 is invalid syntax 😐

paper flower
bitter bone
#

!e

import json

userJohn = {
    "user": "user1",
    "ukey": "1a2b3c4d",
    "uhash": ""
}

userSmith = {
    "user": "user2",
    "ukey": "4d3c2b1a",
    "uhash": ""
}

#user = input("User Please")
chosenUser = 'userSmith'
print(json.dumps((chosenUser)))
kind kayak
#

🤷‍♂️ apparently it is

#

oh there we go

#

user input

delicate fieldBOT
#

@bitter bone :white_check_mark: Your eval job has completed with return code 0.

"userSmith"
bitter bone
#

you need to eval it

kind kayak
#

aight it was just my shitty programming then

bitter bone
#

or make a single json like:

#
{
  "userSmith": ...,
  "userJason": ...
}
kind kayak
#

im completely new to JSON and databases so yeah

bitter bone
#

i would say to go with the latter, since having eval() in the code is not a good habit lemon_sweat

paper flower
#

If you want to use a database then use one 😅

wise goblet
#

JSON is just slightly cooler way of CSV ;b

paper flower
#

And it has nothing to do with csv too

#

🙂

kind kayak
#

i...

#

too many words

#

my brain doesnt def function():

paper flower
#

@kind kayak Look into an orm, for example sqlalchemy or peewee

bitter bone
#

isn't that a overkill for this task

paper flower
#

It would be a good practice

kind kayak
#

i just want a basic login system 😢

paper flower
kind kayak
#

why stuff gotta be so hard

#

databases mean database servers...

wise goblet
#

I remember somewhere old joke

inside the brain:

  • Oh look! pretty girl is on ten o'clock!
  • Oh no, the brain is overloaded, and not functioning anymore!
  • Just kick it!
  • Yes, sir! kicks the brain. Everything is back to normal, sir!
kind kayak
#

think my head is empty D;

paper flower
#

Works for windows

wise goblet
#

oh yes, it was actually reboot perhaps

#

I don't remember it accurately

jaunty galleon
#

mongodb+srv://m001-student:mypassword@sandbox.hytmj.mongodb.net/test

#

What should I replace test with?

wise goblet
#

whatever the name of database inside I guess

#

user database is usually named 'users'

jaunty galleon
#

How do i get the database name?

wise goblet
#

you can connect without specifying database

#

in order to create the first database there

jaunty galleon
#

Why can't there just be a website with all databases names

kind kayak
wise goblet
jaunty galleon
#
import pymongo
from pymongo import MongoClient
from pymongo import mongo_client
print(pymongo.version)
db_link = "My database link"
client = MongoClient(db_link)
db = client.FirstDatabase
people = db.people
name = input("Name? - ")
age = input("Age? - ")
doc = {name: age}
people.insert_one(doc)
print(people.find_one(name))```
It returns None
#

How can I fix it?

#

And is it possible to get the entire people data as a dict? Not to find anything in it? and connect with it from somewhere else

kind kayak
#

it doesnt even have to be secure

#

so idrc what framework

#

i just need to know which one 😂

wise goblet
jaunty galleon
#

I have this document, created with this code:

import pymongo
from pymongo import MongoClient
from pymongo import mongo_client
print(pymongo.version)
db_link = "the link needed"
client = MongoClient(db_link)
db = client.FirstDatabase
people = db.people
name = input("Name? - ")
age = input("Age? - ")
doc = {name: age}
people.insert_one(doc)
print(people.find_one(name))```
If I'll do in another program, db.people will t connect me to the document?
wise goblet
#

at the chapter 5, how to make user login is pretty much explained

#

it it outdated though (but still good!)

#

flask documentation has more up to date version, but less structurized in a right order (section 'Sessions' in flask doc)

jaunty galleon
wise goblet
#

oh

#

sorry

#

I meant to ping person above you

jaunty galleon
#

Oh

pure sleet
jagged cove
#

yo just wanted to ask how important it is to use an async library for the database handling?

#

because i'm making a discord bot and i've always just made normal functions and never had any problems with it

torn sphinx
#

Write a program that will ask the user to input two numbers, and then display the message “They are equal numbers" if they are equal, print "num1 is greater than num2" if the first number is greater than the second number, otherwise print "num1 is less than num2".

#

i need help?

pure sleet
jagged cove
#

yeah and why are u asking this in database channel

torn sphinx
#

im not good at pyhton

#

idk where to ask

#

im new

#

what channel do i use?

jagged cove
#
x = input('give number')
y = input('give more number')
if x == y:
  print('literally the same')
else:
  print('literally not the same')
#

just take a course man

#

codecademy or something

torn sphinx
#

man im not into pyhton

#

i just need to solve my homework

jagged cove
#

look for a course that's free or something and start from there

#

that's how i did it

wise goblet
#

but that's not a problem in my opinion

#

it just motivates to find the right updated commands

pure sleet
#

oh ok

zealous niche
#

hey dudes Im working on a Crud with django Im having trouble with putting up multiple tables with the stuff Ive been digging up I have only been able to get 1 table for my database

#

does that make sense?

jaunty galleon
#

Why MongoDB is so complicated

pure sleet
wise goblet
#

I thought it is supposed to be simple

#

like put to dictionary/ get from dictionary ;b

#

never tried one though

jaunty galleon
#

@burnt turret

burnt turret
#

Yeah, do you know about the difference between find and findOne? (Or find_one when using pymongo)

jaunty galleon
#

I think find returns the entire query?

#

and find one returns a dict by key and value?

burnt turret
#

You didn't word that very well; find will return all documents that matches your constraint

#

Like in your example query in the other channel, if your collection had multiple documents with name set to "nir", findOne will only return one document

torn sphinx
#

pls answer me
how can i get the prefix from the server by guild_id

{
guild_id: "718381882293189182",
prefix: "//"
}
``` i only want the value //
burnt turret
#

find will return all of them in a Cursor object

torn sphinx
#

mongo

jaunty galleon
#

I think i'll do one doc in a collection for a guild

burnt turret
burnt turret
burnt turret
jaunty galleon
#

{"guild_id": "guild_id": the_id, "economy": {"member_id": {"wallet": 0, "bank": 0}}, "suggestions_channel": the_channel_id} maybe like that

torn sphinx
#

hmm

jaunty galleon
#

collection:
doc_a:
{"name": "nir", "skill": "bad af"}
doc_b:
{"name": "test", "skill": "better than nir"}
doing:
test = collection.find_one({"name": "nir"})
and than doing:
skill = test['skill']
will it return bad af

burnt turret
#

Yep

#

skill will be set to "bad af"

torn sphinx
#

oh i got it

jaunty galleon
#

Mmm

#

starting to get a little more understood

torn sphinx
#
{
guild_id:"something",
prefix:"//"
}
``````py
guild = collection.find_one({guild_id:"something"})
prefix = guild['prefix']
```?
burnt turret
#

Yes

torn sphinx
#

how to write data

burnt turret
#

look into collection.insert

jaunty galleon
#

If I would do:
data = collection.find_one({"name": "nir"}) and it's not there, will it return None?

jaunty galleon
burnt turret
#

That was to the other person

#

You do get the full dict?

torn sphinx
#
data = {
guild_id:f"{ctx.guild.id}",
prefix:"//"
}
collection.insert(data)
```?
jaunty galleon
#

Yeah that should work

#

I am going to run a few tests

#

Thanks anand

finite lynx
#

Would an array field be violiting the first rule of 1NF in database normalisation?

flint imp
#

@jaunty galleon You can store the document _id under a member id tho

#

find_one if only one document needed

jaunty galleon
#
from discord.ext.commands.core import guild_only
from discord.invite import PartialInviteGuild
import pymongo
from pymongo import MongoClient
from pymongo import mongo_client
print(pymongo.version)
CLUSTER = MongoClient("The link ya know")
NAMES_DATABASE = CLUSTER["FirstDatabase"]["names_data"]
def tryout():
    options_log = ['log-in', 'log in', 'login']
    options_sign = ['sign-up', 'sign up', 'signup']
    while True:
        sign_or_log = input("Sign up or log in?")
        if sign_or_log in options_sign:
            name = input("What is your name? - ")
            check_if_exists = NAMES_DATABASE.find_one({"name": name})
            if check_if_exists:
                print("This name already exists")
            else:
                skill = input("What is your skill - ")
                ended_dct = ({"name": name, "skill": skill})
                NAMES_DATABASE.insert(ended_dct)
        elif sign_or_log in options_log:
            name = input("What is your saved username? - ")
            check_if_exists = NAMES_DATABASE.find_one({"name": name})
            if check_if_exists:
                skill = check_if_exists.get('skill')
                name = check_if_exists.get('name')
                print(f'Name: {name} \n Skill: {skill}')
            else:
                print("This name is not in the database.")
tryout()```
I just made this I am proud of myself
flint imp
#

use motor

#

its an async version

jaunty galleon
#

Oh no

#

I can't learn something new right now

flint imp
#

Its just an async driver lol

jaunty galleon
#

Is motor part of MongoDB

#

What will I need to change