#databases

1 messages Ā· Page 128 of 1

fading breach
#

(hash the passwords)

burnt turret
#

Are you asking about the functions you'd use to add data to the db?

fading breach
burnt turret
#

Oh, that isn't really a database question then

#

Maybe reserve a help channel

heady hatch
#

Can anyone guide me the right direction.

Whats the best way to structure a database where I have several tables like so: "desk_phones", "printers", "desktops", "Fax" and have a table that called "devices" that accepts any of those tables.

Would it be called many to many relationships, or is that not how it works? I can't seem to wrap my head around the documents for postgesql or sqlalchemy.

In python when you have a an object you can nest a different class object reference in it. I know it doesn't likely translate or work like that with databases, but I could sure use some help understand how something like that is done.

brazen charm
#

seems like a bad datastructure

#

you would have one table called devices

#

and another table called devicetypes or what ever

#

where you can specify the type and its corresponding id there rationalising the data

#

you then in your devices table would have a device_id column which is a foreign key to devicetypes acting as a linking table

#

making a one to many relationship and keeping the data normalised with minimum duplication

heady hatch
#

I think I understand.

#

I'll have to keep looking into this. It's rather difficult to visualize the structure.

#

Thank you.

boreal inlet
#

if the s13 will equal the modoul is will not be able to acsess the database

inner basalt
#

I need some help with my JSON

#

I have a very large data set, but I need it to make it fit my structure

#

I want it to look like this:

#
{"intents": [
        {"tag": "greeting",
         "patterns": ["Hi", "How are you", "Is anyone there?", "Hello", "Good day", "Whats up"],
         "responses": ["Hello!", "Good to see you again!", "Hi there, how can I help?"],
         "context_set": ""
        },```
#

but the data set looks like this

#

the file was too big to upload

#

what can I do so I can make it fit the first structure?

#

I really only what the question and answer part of the json

boreal inlet
#

i am sure we have to add variable (x) to the database every time the user acces it

#

we have to convert all the variables to a string

sinful condor
#

in a mongodb database how do I find something when something else is something

#

like find xp when user = user

#

I am used to sqlite so idk how

burnt turret
#

collection.find({"user":<user>}) will return that user's document ( i.e dictionary with all of that user's data)

#

Then you can just use the keys to access the data

sinful condor
#

ok

#

thank you

#

@burnt turret I have this ping_cmm = {"_id":author_id} collectionfound = collection.find(ping_cmm) print(collectionfound) but it returns an object

#

<pymongo.cursor.Cursor object at 0x7f088e6a8f10>

burnt turret
#

find returns a cursor

#

You can loop over it with a for loop

#

While looping, each item will be a dict

#

In my example I used find_one, because

  1. it directly returns the dict
  2. I assume one user will have only one dict in your collection
#

Find_one will return the first document which matches the filter case

sinful condor
#

ok does that still return a cursor if its directly a dict

burnt turret
#

No

#

Just a dict

sinful condor
#

ok then I will use that

#

because I am making a global level system

burnt turret
#

You use find when you're expecting more values

#

Also, use motor

#

Pymongo is blocking

sinful condor
#

motor?

burnt turret
#

One sec

sinful condor
#

is that like async pymongo

burnt turret
#

Yep

sinful condor
#

ok

burnt turret
#

Except for adding awaits

#

You'd just need to import it and change your MongoClient to motor's equivalent

#

Then add awaits before queries

sinful condor
#

ok yeah I only have that so far so it will be easy

#

so import motor

#

@burnt turret what is motors eqivilent

#

I looked at the docs and tried motorclient but it didnt work

burnt turret
#

Wait a sec

#

AsyncIOMotorClient @sinful condor

sinful condor
#

ok thanks

burnt turret
#

Oh one more thing, while using motor you'll await basically every query except find (you'll await find_one though)

#

This is because find here also returns a cursor, and it doesn't do an IO operation (doesn't ask the db for data) until you try accessing values from the cursor

#

So there are two ways to use it really;

Option 1
data = collection.find() #note the lack of await
async for doc in data:
# note the async for

sinful condor
#

do you put async in getting the db

#
async def mongotest(ctx):
  mongo_url = "mongodb+srv://fireballbot:discord@fireball-discord-bot.5qsqj.mongodb.net/discorddatabase?retryWrites=true&w=majority"
  cluster = motor.motor_asyncio.AsyncIOMotorClient(mongo_url)
  db = cluster["discorddatabase"]
  collection = db["main"]
  author_id = ctx.author.id
  guild_id = ctx.guild.id
  ping_cmm = {"_id":author_id}
  collectionfound = await collection.find_one(ping_cmm)
  print(collectionfound)
  await collection.update_one({"_id":author_id},{"$set":{"Level":1}})```
burnt turret
#

Option 2:
Using motor's to_list method
You will need to await this though
data = await collection.find().to_list(length=10)

sinful condor
#

it returns {'_id': 449756487510654988, 'GuildID': 742942218687479828, 'XP': 0, 'Level': 1}

burnt turret
#

Isn't that what you expect?

sinful condor
#

yes

#

but I have one question how do I get the part inside one of them

#

like the 0 in xp

#

or the 1 in level

burnt turret
sinful condor
#

ok

burnt turret
#

You could also use

#

!d dict.get

delicate fieldBOT
#
get(key[, default])```
Return the value for *key* if *key* is in the dictionary, else *default*. If *default* is not given, it defaults to `None`, so that this method never raises a [`KeyError`](exceptions.html#KeyError "KeyError").
sinful condor
#

ok thank you

fast whale
#

how 1000 calls per 60 seconds can or will affect my postgresql database?

burnt turret
#

It won't run into problems, if that's what you're asking

#

Databases can handle much more

fast whale
#

yeah thats what I meant, thanks!

trim lintel
#

Hello

#

How to get help with database question?

velvet coyote
#

by asking it?

lapis wind
#

so I just switched my bot over to mongoDB and now everything is rly slow

#

anyone know how I can speed it up?

#

I'm using motor.motor_asyncio.AsyncIOMotorClient

trim lintel
#

So I want to learn how to make a user wishlist for products. Like how to design table. Which I use relationship?

trim lintel
velvet coyote
#

right, i only know postgres. though

trim lintel
#

Yeah but I think is the same for all

frail hazel
#

Any recommended books for database design?

velvet coyote
trim lintel
#

What?

#

Im confuse

torn sphinx
#

Can I use mongodb functions without worrying about them blocking?

sinful condor
#

how do I get the rank of someone in a collection in mongodb

burnt turret
#

Those concepts are similar across databases if I understand correctly

burnt turret
#

#databases message @torn sphinx read messages from here, I explain the basics of switching from pymongo to motor

burnt turret
sinful condor
#

here are some of them

#

I am trying to rank it by xp

burnt turret
#

So you want the person with highest XP to be rank 1?

sinful condor
#

yes

burnt turret
#

One sec, lemme refer something

#

Off the top of my mind you could pass {"$sort":{"XP":1}} into find()

sinful condor
#

ok

burnt turret
#

Did you understand what this does?

#

@sinful condor

sinful condor
#

it sorts it I tried sort but couldnt figure it out

#

it sorts it I think descending

burnt turret
#

It sorts it in ascending order by XP

#

Oh I'm not sure actually

sinful condor
#

one sec I hav e the docs

#

ascending is 1

#

descending is -1

burnt turret
#

Instead of 1/0 i usually pass pymongo.ASCENDING constants

#

Right so you'd do -1

sinful condor
#

ok

burnt turret
#

And then do you remember how to get list from cursor of find()?

sinful condor
#

no I never actually did that I jsut changed it to findone

burnt turret
#

I'd told you two methods to get the values from a result of find

sinful condor
#

ill go look one sec

burnt turret
#

Right, you don't want to sort in a find-one you want to use find

sinful condor
#

yeah

#

I am getting an object I just need to turn that into whatever it makes

burnt turret
#

Will give you [{actual data of user with highest XP}]

sinful condor
#

ok

burnt turret
#

It'll be in a list, so you'd have to do result[0] to get the dict inside

sinful condor
#

I will do 5 but also

burnt turret
#

Yeah that'll give you 5 highest

sinful condor
#

how do I get the rank of the specific user like even if they are something super high like 100

burnt turret
#

šŸ¤” lemme think that through

#

I can't think of a way to make the database do the work in that case šŸ¤” the easy way seems like sorting by descending order and then looping through all of them to find which number the specific user is at

sinful condor
#

ok

#

I am getting an error on the top 5 rank

#

rankfound = await collection.find({"$sort":{"XP":1}}).to_list(length=5)

#

pymongo.errors.OperationFailure: unknown top level operator: $sort, full error: {'operationTime': Timestamp(1610739908, 1), 'ok': 0.0, 'errmsg': 'unknown top level operator: $sort', 'code': 2, 'codeName': 'BadValue', '$clusterTime': {'clusterTime': Timestamp(1610739908, 1), 'signature': {'hash': b'\xfb\xd9\x9bf\x80Q\x8f\x07Xq\x86M\xa0\xef\x0b~;4\x97\xd5', 'keyId': 6916547034908459011}}}

burnt turret
#

You need to pass two dicts

#

The first dict is what you'd call a filter

#

It filters through the data to match

#

In your case you dont really want to match anything

#

So, pass {}

torn sphinx
burnt turret
#

And then the sorting doctor second

sinful condor
#

where should I put it in there

burnt turret
sinful condor
#

rankfound = await collection.find({"$sort":{}{"XP":1}}).to_list(length=5)

torn sphinx
#

tysm

burnt turret
sinful condor
#

oh ok

burnt turret
#

As you can see we passed in two dicts, first filter -empty dict because we want to get everything, second is telling how to sort

sinful condor
#

im still getting an error I think its different though

#
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1471, in _retryable_read
    return func(session, server, sock_info, slave_ok)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1360, in _cmd
    return server.run_operation_with_response(
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/server.py", line 135, in run_operation_with_response
    _check_command_response(first, sock_info.max_wire_version)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/helpers.py", line 160, in _check_command_response
    raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: Unsupported projection option: $sort: { XP: 1 }, full error: {'operationTime': Timestamp(1610740138, 1), 'ok': 0.0, 'errmsg': 'Unsupported projection option: $sort: { XP: 1 }', 'code': 2, 'codeName': 'BadValue', '$clusterTime': {'clusterTime': Timestamp(1610740138, 1), 'signature': {'hash': b'\xf1\x17\xfe\xd1)\xc9\\\xb9\x97-%\xf861\xff\xf7k\xb6\xc3\xc2', 'keyId': 6916547034908459011}}}```
#

rankfound = await collection.find({}, {"$sort":{"XP":1}}).to_list(length=5)

burnt turret
#

I'm on mobile reading that is difficult

#

Also we want to sort descending, -1 but that's not the issue

sinful condor
#

I think this is the main part

#

Unsupported projection option: $sort: { XP: 1 }, full error: {'operationTime': Timestamp(1610740138, 1),

burnt turret
#

Lemme think one sec

rain plank
#

What's the difference between motor and pymongo besides motor being asynchronous

burnt turret
#

Modify the query actually, to do
cursor = collection.find()
cursor.sort("XP":-1)
data = await cursor.to_list(length=5) @sinful condor

burnt turret
#

Just adding awaits before queries

rain plank
#

Probably should have asked if there's any difference at all

burnt turret
#

Internally motor is just running pymongo functions on greenlets

sinful condor
#

@burnt turret TypeError: if no direction is specified, key_or_list must be an instance of list

torn sphinx
#

Is this the correct syntaxpy cluster = motor.motor_tornado.MotorClient("mongodb+srv://<name>:<password>@<db>.pq3r5.mongodb.net/<dbname>?retryWrites=true&w=majority")

sinful condor
#

on this line cursor.sort({"XP":-1}) do I need to add a second one

burnt turret
#

No dict

#

Did I put a dict into cursor.sort? My bad

sinful condor
#

you didnt

#

I added it because it was a syntax error in there

#

on the -1

burnt turret
#

instead of -1 try pymongo.DESCENDING

sinful condor
#

in there

burnt turret
#

you'd have to import pymongo for that constant though oof

sinful condor
#

like "XP":pymongo.Descending

burnt turret
#

Yep

sinful condor
#

ok

burnt turret
#

All caps descending

#

It's a constant, -1

sinful condor
#

still invalid syntax cursor.sort("XP":pymongo.DESCENDING)

burnt turret
#

Oh wait @sinful condor it’s meant to be a comma between xp and -1 not :

#

My bad

sinful condor
#

oh oik

#

ok it works now

burnt turret
#

That's great!

sinful condor
#

so how should I do the single user rank again

#

is there a way to save rank as something like there is in sql

burnt turret
#

How would you save in SQL?

sinful condor
#

one sec

#

this was my rank in sql select userguild, xp, level, (select 1 + count(*) from level as p2 where p2.xp > p1.xp) as user_rank from level p1 where userguild=? order by xp desc

burnt turret
#

Right SQL makes those queries so much simpler

#

There's no easy way to do it with mongo, you'd have to mess around with some aggregation pipelines I tjink

sinful condor
#

yeah it was even simpler before I had to go into an earlier version

#

it was rank as userrank

#

instead of that complicated thing

#

ok ill try to work it out later

#

@burnt turret thanks for helping me my aiosqlite database broke when my bot got too big for sqlite a couple of days ago

proven arrow
#

A user can have many products. A product can belong to many users.

trim lintel
#

Ah

#

So how this will look?

proven arrow
#
users
- id (PK)
- email

products
- id (PK)
- name

user_products
- id (PK)
- user_id (FK references users table)
- product_id (FK references products table)
- UNIQUE (user_id, product_id)
#

You dont need the surrogate key id in the user_products table but i like to have it.

trim lintel
#

Yeah I understand. Ok thanks you, let me try this hold on

#

Ok done this now how to make query?

#

For like say I want to get all wishlist items for user equal something?

proven arrow
#

If you want data from both sides.

SELECT u.email, p.name FROM user_products up
JOIN users u ON up.user_id = u.id
JOIN products p ON up.product_id = p.id
WHERE up.user_id = some_id;
#

If you just want details of the products then you dont need to join on the users table.

trim lintel
#

Yes nice !!

#

@proven arrow I can message you in private you sir if I need help?

proven arrow
#

No i am not your consultant šŸ˜…

#

Just ask here

trim lintel
sharp bobcat
#

Is there some library to support asnyc postgres ORM?

#

I know that there's asyncpg, but that doesn't have ORM

bright pawn
#

I've only just started playing with it, but Tortoise ORM is essentially an async implementation of the Django ORM, and it uses whatever async engine you want under the hood (e.g. asyncpg): https://tortoise-orm.readthedocs.io/en/latest/

#

I wouldn't classify it as "production ready" though

sharp bobcat
#

yeah, I was just looking through the FAQ of asyncpg and looks like SQLAlchemy had an update to 1.4 which added the possibility of the use of an async engine, last time I checked this wasn't there so I didn't know, but thanks for the suggestion

sinful condor
#

In mongodb does anyone know a way where I can get the get the rank of a something in a whole collection based on one thing

#

Ping me if you know how

torn sphinx
#

Building my database is taking way too long with the method I'm using.
I'm building a database with comment and replies (reddit dataset), problem is, the dataset is just comments. To get around this, I iterate through the dataset and add each comment with the relevant data to the database. Since there is a commentID and authorID, I can match those to get Comment-Reply data (to train a chatbot with). What I'm having an issue with is finding the parent comment, I use the mongodb "find_one" method. I do this each iteration that I add a comment to check if the comment I'm adding has a parent comment that it's replying to. As I add more and more, I believe the "find_one" method iterates through the entire database to find the match, as I add more and more comments this takes longer and longer each iteration and it's just not working.. Is there any way I can speed this up??

#

Wow. I removed the function that finds the parent comment just to see the time difference.
With Parent Comment Function
10k Comments | 30 Seconds
Without Parent Comment Function
330k Comments | 20 Seconds

pure cypress
#

I think I left a comment about your question the other day

#

Hmm maybe not. The other question was about sqlite

torn sphinx
#

Yeah

#

I switched to MongoDB and figured out how to use that to see if it was any better

pure cypress
#

I don't know anything about mongodb or no-sql in general, sorry

torn sphinx
#

I ended up going to sleep, and just got back to work and did some testing to further figure out the issue, so I posted a more I guess "accurately" detailed explanation

pure cypress
#

In a relational database the solution is to index the column so the lookups are fast

torn sphinx
#

Index the column so lookups are fast?

pure cypress
#

Yeah I mentioned it the other day

torn sphinx
#

yeah just went back to look at what you said

#

My sqlite3 table was constructed like so

Cursor.execute("CREATE TABLE IF NOT EXISTS RedditComments(ParentID TEXT PRIMARY KEY, Parent TEXT, CommentID TEXT, Comment TEXT, Subreddit TEXT, Score INT, Unix INT)")```
And the lookup function was like this
```py
def FindParent(ParentID):
    try:
        Cursor.execute(f"SELECT Comment FROM RedditComments WHERE CommentID = '{ParentID}' LIMIT 1")
        Result = Cursor.fetchone()
        if Result != None:
            return Result[0]
        else: return False
    except Sql.Error as Error:
        print("FindParent", Error)
        return False
pure cypress
#

It should be significantly faster if the ID column has an index or is the primary key. If it already was and was still slow, then I'm not sure how to speed it up.

#

Should the CommentID be the primary key, not the ParentID ?

#

Is there a specific reason you make the parent the primary key?

torn sphinx
#

No, there wasn't a specific reason, I don't believe it matters? I just had it organized that way

pure cypress
#

Yes it absolutely matters

torn sphinx
#

Oh

#

I'm very new to sqlite and databases in general, this is kinda my introduction so I'm not too certain with what I'm doing

pure cypress
#

Not only from a performance perspective but also from a database design perspective

torn sphinx
#

Oh

pure cypress
#

The primary key is meant to signify the column that uniquely identifies the row

#

The PK column automatically gets a unique index created for it.

torn sphinx
#

Oh, and because I'm finding where the commentID = "whatever", it'll be faster if the CommentID is the PK column?

pure cypress
#

Yes

torn sphinx
#

Ohhhh, okay, that makes sense, though I'm still confused about table IDs, I don't have one defined in my table, unless that would be the PK column..?

pure cypress
#

But also consider that many comments can have the same parent, so using a parent as the unique identifier is wrong.

torn sphinx
#

Ohh, that makes a lot more sense

pure cypress
#

The PK is what is commonly referred to as the table's ID

torn sphinx
#

Oh okay, but since I'm iterating through the table every iteration I add a comment, it'll still get exponentially slower even if I do that, right?

#

Even if I have a properly setup PK?

pure cypress
#

Why would you iterate through the table every time a comment is added?

torn sphinx
#

To see if that comment I'm adding has a parent comment, so to see if that comment is replying to another one, I then pair them

#

The way I'm doing this is just structurally flawed I believe, but I don't know how else I could do it

pure cypress
#

But if it has a parent ID, don't you already know it has a parent comment?

torn sphinx
#

Hmm... I guess if it has a parentID, I could then find the matching commentIDs in the dataset itself rather then trying to match it in the database each iteration..?

pure cypress
#

Does the dataset provide the parent ID for you already?

torn sphinx
#

This is the data each comment has

pure cypress
#

It's a screenshot so it's hard for me to tell if it has the parent ID

torn sphinx
#

It has parentID

#

and "id" which is the ID of the comment

#
RowCount += 1
Row = Json.loads(Row)
CommentID = Row['id']
Comment = Functions.FormatData(Row["body"])
ParentID = Row["parent_id"].split("_")[1]
#Parent = Functions.FindParent(ParentID)
Parent = "None"
Subreddit = Row["subreddit"]
Score = Row["score"]
Unix = Row["created_utc"]
Time = Functions.UnixConvert(Unix)```
#

That's the information I'm taking

pure cypress
#

Insert all the comments into your database. Once they're all inserted you can quickly get the parent comment for any given comment just using the WHERE clause like you already were.

torn sphinx
#

So, insert all of them as I was, make sure the CommentID is the PK, after it's finished inserting, loop through the database(?) and if a comment has a parent, remove the parent and add the parents comment body to the parent portion of the current comment to form a comment-reply dataset?????

#

I thiiiinkkk???

pure cypress
#

Yes, you could do that

#

However, from a pure db-perspective, that is bad design

#

Since you're de-normalising the data by adding the parent comment to the child comment.

#

I don't know what else you need the database for

torn sphinx
#

Ohh I see what you mean.. though if I'm making a chatbot with this, wouldn't I need to lookup the parent comment each time? I'm not at the portion of making a chatbot and I'm still teaching myself about it, but I think having straight up comment-reply structure would make that a lot easier to train?

pure cypress
#

But it may be better to keep that merged text content separate from the original tables

#

I don't know anything about training, so I can't comment on what kind of data structure would be best.

torn sphinx
#

That's fair, thanks for the help though

#

This was really insightful and nice

pure cypress
#

The problem I see with merging the content into the table is that the rest of data becomes inaccurate.

#

Like the author, date, etc

#

Since now the text is that of multiple comments

#

You'd somehow need to reconcile that

torn sphinx
#

Oh

#

Yeah I'd need to have parent score and time if I were to do something like that huh..

#

hmm

pure cypress
torn sphinx
#

Alright, thanks

#

šŸ‘

#

If I'm updating the table's row to set the ChildComment's ParentComment, ParentScore, and ParentUnix to the ParentComment's details... the ParentID is the same as the CommentID, which is how I match them... but if I want to update the ChildComment to add the ParentComment's details.. how would I know which I'm using if I'm searching with the term "WHERE CommentID = {ParentID}" because, doesn't that apply to both the ChildComment and the ParentCommen..?

#

And if I'm doing this, how would I remove the ParentComment and keep the ChildComment..?

#

That's hellishly confusing but I hope I got my question across lol

#

@pure cypress

pure cypress
#

Sorry I didn't quite follow.

#

I'm off for the night anyway so hopefully someone else can help you out

#

Otherwise I'll try to respond tomorrow

torn sphinx
#

Yeah it's alright, cya

torn sphinx
#

I GOT IT WORKING WOO

#

Thanks mark!

crimson needle
#

what is difference between = and IS. In this query```sql
SELECT
company,
st,
st_copy
FROM meat_poultry_egg_inspect
WHERE st IS NULL -- if used = instead of IS this returns nothing (no error though)
ORDER BY st;

torn sphinx
#

you can't use = to do a NULL comparison

#

more detailed answer

crimson needle
#

thanks

agile laurel
#

is there away to reset all databases with a command?

#

like reset all number to 0

burnt turret
#

Elaborate

agile laurel
#

so i am working on a leveling bot for discord.

burnt turret
#

You have multiple databases? Or one database with multiple collections?

agile laurel
#

one database

#

with one collection

burnt turret
#

right

agile laurel
#

there alot of users so i dont want to manually reset all of there xps

#

that takes tons of times

burnt turret
#

Do all the documents have the same structure?

agile laurel
#

yes

#

what do u mean by the same structure

#

like are they in one database if so

#

yes,

burnt turret
#

Same key value pairs in each user's dict

agile laurel
#

yes

#

same data

#

but different value

burnt turret
#

So you'll use collection.update_many

agile laurel
#

for example bot has 20xp and dirk has 30xp

burnt turret
#

As our want to change everyone's XP, you want the query to match everyone

agile laurel
#

yes,

burnt turret
#

so
collection.update_many({}, {"$set":{"XP": 0}})

agile laurel
#

ok

burnt turret
#

This sets everyone's XP to zero

agile laurel
#

let me try

#

but

#

one prob

burnt turret
#

But that is assuming you have a key called XP

agile laurel
#

it doesnt remove there roles.

#

:/

burnt turret
#

What do you mean?

agile laurel
#

the roles they got assigned when they leveled up

burnt turret
#

Obviously those won't be removed when you update the db

agile laurel
#

yes

#

but i want them to be removed

#

i guess

#

thats gonna be another story

#

:/

burnt turret
#

That's a dpy question now lmao

agile laurel
#

ok

#

lets move there

burnt turret
#

Loop through guild.members and remove roles

agile laurel
#

ok

thorny pivot
#

If I want to build a calculator (for empirical formulas), but the equation is unknown (User input).

Is this the right way of going about with my data scheme?
def function_name(data_1, data_2):

Where one table is for the equation (id, data_1, data_2 ... data_nth) and my 2nd table is for the input parameters (relates back to the equation table but for the values).

Is there a better way to do this, instead of having a Table with 100 columns (unknown amount)

torn sphinx
#

Anybody know the format that 0x454D424 would get stored in a database as? It's not a string or an INT, BLOB doesn't seem to work either

wheat umbra
#

@torn sphinx you can convert it into INT

torn sphinx
wheat umbra
torn sphinx
#

INSERT INTO table (id, data) VALUES (6345, 0x454D424480) basically

#

there's no '' around the data so it's not a string and there's both letters and numbers so it's not a INT either

proven arrow
#

@torn sphinx what's the error?

#

Its probably because that value is out of the int size

#

Change it to bigint and will work.

torn sphinx
#

it can't be an int with an x in it can it?

proven arrow
#

That's fine yes, it will just convert it to a decimal value for you.

torn sphinx
#

Hmmmmm

#

ok thanks I'll take a look

#

@proven arrow I probably should have mentioned I wasnt posting the full length of the data, its over 1000 characters long

#

bigint max is 255

proven arrow
torn sphinx
#

@proven arrow I'm getting an out of range error when trying to insert the data

proven arrow
#

Well what type are you using?

#

Use one of the text type then

torn sphinx
#

bigint

proven arrow
torn sphinx
#

Im not even sure why this wasnt stored as a string in the first place

#

05:17:23 [ERR][SQL Editor Form]: Error Code: 1366. Incorrect string value

wheat umbra
#

bigint didn't work?

torn sphinx
#

nope, out of range apparently

wheat umbra
#

how long is the hex value

torn sphinx
#

over 1000 characters

wheat umbra
#

a single one?

proven arrow
#

Then use a text type like I said?

torn sphinx
#

Incorrect string value: '\x80\x00\x00\x00\xCB\xD5...'

#

thats what I get for TEXT column type

proven arrow
#

What encoding do you have for that column?

torn sphinx
#

not sure, I think the table is latin-1

proven arrow
#

Try changing it to utf8mb4

torn sphinx
#

I changed the column but the table has data that cant be changed to utf8

#

still doesnt work

#

seems I am able to insert the data in the goofy ($#W&($#(@#$(* looking char set with the latin-1 setting and TEXT type column but I dont think this is the right way

coarse prism
#

can someone help me with an apache starting up error?

bleak crown
#

Hi i have a discord bot and currently i'm developing an Ambiance Music bot for rpg sessions

#

So in that bot, Game Masters will be able to save their ambiance music with a keyword + optional changes like thumbnail, what bot will say when ambiance will played.

#

I'm asking should i open a new table for each person that will use the ambiance system?

#

Or should i just compress them to one table and check if it's gm's id all the time

#

Which way is the most efficient and sensable way?

#

Btw i'm using aiosqlite

burnt turret
#

one table, track user IDs

bleak crown
#

Hmm and if you would like to

#

Can you explain the logic behind this choice?

#

(I'm kinda new to databases)

burnt turret
#

you'd have one column with the user's id, and other columns for the other stuff, and then the next time someone uses the command you'd check your database for that user's ID

#

Making a new table everytime is a wasteful method I think

bleak crown
#

But they will not only use one column

#

Like for an example they'll insert 50 column

burnt turret
#

What all data would you be storing for a user?

burnt turret
bleak crown
#

Actually rows are for the ambiance keys

#

oh sorry

#

rows*

#

Like they will type !insert-ambiance winter, youtube_link, other stuffs

burnt turret
#

Isn't it fixed how many other things will be there?

bleak crown
#

Uh nope, other things will be null and they are optional for the user

#

but first two things are not optional

burnt turret
#

Right, so what's your question exactly now?

bleak crown
#

So is it better to create a table for each person and insert the ambiance row to that table

#

Or just compress them to one

burnt turret
#

One table is better I think

#

And that's why I said, to identify who's ambience a row is representing you'd add a user-id column

bleak crown
#

So i'll do PRIMARY KEY(user_id, ambiance-name) yeah

burnt turret
#

šŸ¤” a user could appear multiple times right?

bleak crown
#

Yeap, like actually more than 10 in average

burnt turret
#

And shouldn't multiple users be allowed to have the same ambiance?

bleak crown
#

Uh they can actually

burnt turret
bleak crown
#

Yeah šŸ˜„

burnt turret
#

You could use NOT NULL on the compulsory columns

#

Like user id, ambiance

bleak crown
#

Hmm what NOT NULL does? Actually i can check it too

#

Also i would like to do commands like !take-profile Game Master's Name

burnt turret
#

As the name suggests a value in that column can never be Null (you can't leave that empty for any user)

bleak crown
#

So they will be able to use another person's ambiance list

burnt turret
#

Right so in that case in your query you'd do
SELECT .... WHERE user_id=other person's id

bleak crown
#

Yeap, okay so we are agreed in 1 table šŸ˜„

#

Got it

#

Thank you for the help ā¤ļø

#

I thought lufthansa-pilot was the only person that was looking here šŸ˜„

burnt turret
#

Lmao he is the reliable regular here, I pop in once in a while

wheat umbra
#

he sure is

fading breach
#

Hi, I want to update my mongodb document, but every time I try it, it says must be an int. How do I update with a string?

sinful condor
#

you could just do int()

#

around the str as long as its numbers

fading breach
#

@sinful condor its not numbers

#

they are all str

sinful condor
#

oh ok then idk

sinful condor
#

why does this not work guild_id = ctx.guild.id ping_cmm = {"_id":guild_id} collectionfound = await collection.find_one(ping_cmm) ping_cmmm = {"_id":guild_id, "Prefix":prefix} if collectionfound is None: await collection.insert_one(ping_cmmm) await ctx.send(f"Prefix has been set to ``{prefix}``", delete_after=10) else: await collection.update_one(ping_cmmm) await ctx.send(f"Prefix has been updated to ``{prefix}``", delete_after=10)

#

it doesnt change the prefix

burnt turret
#

Because the syntax for an update and an insert is different @sinful condor

#

If you'll see, an insert needs just one dict, and it'll insert that dict into the db

#

An update needs two dicts, one dict is to filter through the db and specify which document to update, and the second dict contains the new data that we want to use

#

What you should be doing is an upsert

#

When you pass upsert=True to update, it'll
up_date a document if it matches,
but if nothing matches, it will in_sert

burnt turret
#

You might be trying to $inc with a string, when you should be using $set, but I'm guessing without seeing code

fading breach
#

im using $set now

burnt turret
#

Ah, alright šŸ‘

sinful condor
#

oh yeah I forgot about that

#

@burnt turret I dont really understand how to do upsert but I made it so it was 2 if collectionfound is None: await collection.insert_one(ping_cmmm) await ctx.send(f"Prefix has been set to ``{prefix}``", delete_after=10) else: ping_cmmmm = {"_id":guild_id},{"$set":{"Prefix":prefix}} await collection.update_one(ping_cmmmm) await ctx.send(f"Prefix has been updated to ``{prefix}``", delete_after=10) but it still doesnt work

burnt turret
#

And you're passing that tuple into the query

#

You need to be passing the two dicts inside the tuple, you can do that with
await collection.update_one(*ping_cmmmm)

sinful condor
#

ok

#

@burnt turret this still doesnt work collectionfound = await collection.find_one(ping_cmm) ping_cmmm = {"_id":guild_id, "Prefix":prefix} if collectionfound is None: await collection.insert_one(ping_cmmm) await ctx.send(f"Prefix has been set to ``{prefix}``", delete_after=10) else: ping_cmmmm = {"_id":guild_id},{"$set":{"Prefix":prefix}} await collection.update_one(*ping_cmmmm) await ctx.send(f"Prefix has been updated to ``{prefix}``", delete_after=10)

burnt turret
#

What happens?

sinful condor
#

nothin

#

no error but it just doesnt change it

#

it runs the update code but nothing happens

burnt turret
#

I'm on mobile so this code is tough to read, could you just screenshot this and send an image please?

sinful condor
#

yes

burnt turret
#

Why is it indebted so much?

#

Indented*

sinful condor
#

idk just is, it doesnt hurt it

burnt turret
#

Are you sure?

sinful condor
#

yes because the command works

#

just it doesnt update it in the database

burnt turret
#

It gives you message output?

sinful condor
#

yes

#

it gives me the prefix has been updated one

burnt turret
#

assign the result of the update_one and print it

#

Tell me what you get

sinful condor
#

like update = update_one

burnt turret
#

update = await collection.update_one...
print(update.matched_count, update.modified_count)

sinful condor
#

its not printing anything

burnt turret
# sinful condor

Also I see you're making an instance of motorclient every command - that's unnecessary
In your main bot file, after you do
bot = commands.Bot(commands_prefix=...)
you should do
bot.db = motor.motor_asyncio.AsyncIOMotorClient(url)

This attaches that MotorClient instance to a variable on your bot

So wherever you need the db you can do bot.db (in a cog that's self.bot.db)

burnt turret
sinful condor
#

wait one sec

#

@burnt turret it printed 1 1

burnt turret
#

That means it worked

#

It matched 1 document for your guild, and updated it too

sinful condor
#

ok this time it worked

#

um I didnt change anything

burnt turret
#

Alright nice, read what I said earlier though

sinful condor
#

ok

burnt turret
#

Making an instance everytime is unnecessary, you attach it to a bot variable

sinful condor
#

ok

#

ill do that

torn sphinx
#

Anybody good with pandas here? I cannot seem to find a way to return the index number of a row. I need to do this because I need to find the # of rows of the column and I believe that becuase of the way it was written, getting the last index will not work

#

So I am trying to get the index value of a specific row, but there appears to be no way to do this with pandas

#

It looks like I can easily use .loc to enter and index number and get the value at that index, but there's really no way to do the reverse?

torn sphinx
#

Figured out the solution to this problem. However, we not have an even bigger problem - for some reason pandas is truncating rows and ignoring some values in the same row. I am not sure why this is.

wind tundra
solar pollen
#

How should I check if an item exists in a table before inserting? Or should I just insert and error handle for primary key duplication? (postgres)

brave bridge
solar pollen
#

lol

#

Thanks!

torn sphinx
acoustic silo
#

so for example:

INSERT INTO things (name, age) VALUES ('super', 207) ON CONFLICT DO NOTHING;
#

or use a different expression after ON CONFLICT if you want to update instead, etc.

torn sphinx
#

yo @acoustic silo

#

could you please help me

#

nvm

acoustic silo
#

alright

torn sphinx
fallen vault
#

What am i doing wrong here cursor.execute(f"""INSERT INTO users VALUES({dis},{user_id}, '{name}', NULL, NULL;""")

torn sphinx
#

not sure if thats the issue but this query should be in the format

#

INSERT INTO users (dis,user_id,name) VALUES (%s,%s,%s)

#

something along those lines

fallen vault
#

oh so i cant pass values using f strings?

torn sphinx
#

you can you just need to add this part (dis,user_id,name) with the name of the desired columns

#

cursor.execute(f"""INSERT INTO users (dis,user_id,name) VALUES({dis},{user_id}, '{name}'""")

fallen vault
#

Still not updating 😦

#
            VALUES({dis},{user_id}, NULL, NULL, '{name}');""")```
torn sphinx
#

you are trying to insert 4 parameters but you are passing 5 values

fallen vault
#

Theres 5

torn sphinx
#

oh my bad

fallen vault
#

Dis
id
name
date
phone

torn sphinx
#

no clue are you sure the columns are named correctly they need to match your database

fallen vault
#

Yeah i have pgadmin up as well to verify and run SELECT * FROM users to see if the information has been added

#

Even ran the statement in pgadmin to make sure it works.

#

!paste

torn sphinx
#

no idea sorry

fallen vault
#

Okay thanks

#

i forgot connection.commit() facepalm

torn sphinx
#

lol

#

did it work?

fallen vault
#

Yes. I was adding the information but i wasnt saving it.

#

Went back and change the if statement so now it reads like this ```py
cursor.execute(f"SELECT * FROM users WHERE id ={user_id}")
data = cursor.fetchall()
if data != None:
print(data)
await ctx.send(data)
else:
cursor.execute(f"""INSERT INTO users (dis,id,start_date,phone,name)
VALUES({dis},{user_id}, NULL, NULL, '{name}');""")
connection.commit()
await ctx.send('You have been added')

#

Changed it to fetchone because thats the right one to use im pretty sure

burnt turret
torn sphinx
#

im having difficulties adding a table with two foreign keys in sqlalchemy

pastel oyster
#

hello

#

i have a problem with mysql

torn sphinx
#

@pastel oyster is server of yours running?

#

mysql server

pastel oyster
torn sphinx
#

idk depends how you download it

#

for me i use a program to start it, but for your might be you have to do from command line or however you downloaded it

pastel oyster
#

and i click "full installl"

delicate fieldBOT
#

Hey @pastel oyster!

It looks like you tried to attach file type(s) that we do not allow (.msi). We currently allow the following file types: .3gp, .3g2, .avi, .bmp, .gif, .h264, .jpg, .jpeg, .mkv, .mov, .mp4, .mpeg, .mpg, .png, .tiff, .wmv, .psd, .ai, .aep, .xcf, .mp3, .wav, .ogg, .webm, .webp, .flac, .afdesign, .m4a, .csv.

Feel free to ask in #community-meta if you think this is a mistake.

pastel oyster
torn sphinx
#

hmm well i have never used that method to install, but you can try searching from mysql applications folder and it maybe has some program to start it

pastel oyster
#

ok

torn sphinx
#

maybe its called "MySQL server"

pastel oyster
#

it is no working with app

#

how to do it using cmd?

torn sphinx
#

type in mysql in search bar, and show me what appears?

#

in your windows search bar

#

anyone wants to help with sqlalchemy

#

what is that?

pastel oyster
wheat umbra
torn sphinx
#

oh what you need help with?

torn sphinx
# pastel oyster

try the option "MySQL shell" or then "Mysql 8.0 command line client"

pastel oyster
#

ok

#

what i must to do now?

wheat umbra
#

that's a shell

torn sphinx
# wheat umbra what's the problem?

im trying to record msges sent between two users using a table called messages it has 2 foreign keys referring to both users, problem is i cant get it to work sqlalchemy is giving me errors and im not getting this relationship and backref setup i tried a lot of online solutions nothings working

wheat umbra
#

you need server

torn sphinx
#

@pastel oyster now try running from python

pastel oyster
pastel oyster
#

but it is no appering

#

as normal app

torn sphinx
#

`class Messages(db.Model,Base):
tablename = 'message'
message_id = db.Column(db.Integer,primary_key=True)
sender_id = db.Column(db.Integer,ForeignKey('user.user_id'))
receiver_id = db.Column(db.Integer,ForeignKey('user.user_id'))

class User(db.Model,Base):
tablename = 'user'
user_id = db.Column(db.Integer, primary_key=True)`

pastel oyster
#

ok

torn sphinx
#

i removed the extras to make it clear

torn sphinx
#

Could not determine join condition between parent/child tables on relationship Messages.sender - there are multiple foreign key paths linking the tables. Specify the 'foreign_keys' argument, providing a list of those columns which should be counted as containing a foreign key reference to the parent table.

pastel oyster
#

It is no working

#

can you give me good installer for Mysql?

torn sphinx
#

tried those solutions

wheat umbra
#

it's for flask right?

torn sphinx
#

yes

wheat umbra
#

ok. What is that "Base" in your model

torn sphinx
#

just a generic configuration for the database i think

wheat umbra
#

ok

wheat umbra
torn sphinx
#

ok

lime tide
#

I made a very simple quotation database which allows me to sort by name (its a quote database for me and my friends). I was wondering if there was a way to set the values from False to true easier? Let me know if there is a way (The red is there to cover up some of the active quotes)

trim lintel
#

Helo, so i have these queries for my shop.

select * from products;
select * from brands where id = 1
select * from brands where id = 2

The first query is getting products then the second two is getting the maker of this product.

#

It is working, but the issue is that its making the last 2 queries in a for loop so if i have 100 product, then it makes 100 queries, or if 1000 products then 1000 queries. How to avoid this?

proven arrow
#

Nice, N+1 spot šŸ‘

#

You can eager load them which is basically loading them in advance, to avoid this kind of thing.

#

For example,
select * from brands where id in (1,2)
When you have more products you just pass in the brand IDs which you already have from the select products query.

trim lintel
#

ohhhh yeah yeah i see makes sense this, was more easier than i assumed šŸ˜†

#

i thought maybe i had to write some more complex stuff but ok

proven arrow
#

Yeah that is it, if you want more info on it just Google N+1 problem. It's a common thing people overlook especially when using orms.

fallen vault
burnt turret
#

yep

fallen vault
#

Someone sent me aiopyql so ima rewrite my check and see how I do with just the api document and GitHub code. Wish me luck.

fallen vault
#

40 minutes before i figured out ssl='required' is needed for this to work. I hate api sometimes.

knotty gyro
#

how to increment by 1 in MySQL?

slender rose
#
    await con.execute("""

                    CREATE TABLE profiles(

                    id bigint (50) PRIMARY KEY,

                    name varchar (3000),

                    age varchar (3000),

                    location varchar (3000),

                    dob varchar (3000),

                    height varchar (3000),

                    looking varchar (3000),

                    hobbies varchar (3000),

                    bio varchar (3000),

                    time bigint (50)
                    
                    )
                    
                    """)```
any idea why this code gives this
```Py
Traceback (most recent call last):
  File "abc.py", line 51, in <module>
    loop.run_until_complete(db_connection())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "abc.py", line 16, in db_connection
    await con.execute("""
  File "/home/ubuntu/.local/lib/python3.8/site-packages/asyncpg/connection.py", line 295, in execute
    return await self._protocol.query(query, timeout)
  File "asyncpg/protocol/protocol.pyx", line 316, in query
asyncpg.exceptions.PostgresSyntaxError: syntax error at or near "("```
ivory sky
# slender rose ```Py await con.execute(""" CREATE TABLE profiles( ...

since PG doesn't tell you which line the syntax error occurred on, try removing all columns except for the first and running it, see if you get an error. if not, add the next column and try again. eventually you will find which column definition is causing the syntax error. my hunch is that the space between varchar and (3000) is not allowed, but i'm not 100% sure without testing and i'm not at my computer at the moment

slender rose
#

oh okay thanks lemme try

ivory sky
#

same goes for the space after bigint and (50)

slender rose
#

I remoced them all and still same issue

#

then I tried removing all columns and try see which column has the problem

#
    await con.execute("""

                    CREATE TABLE profiles(

                    id bigint(50) PRIMARY KEY
                    
                    """)
#

this was my code

#

and it still gives the error so probably the issue is on line 1

proven arrow
#

Remove the values for bigint

#

You don't need to give bigint a value

ivory sky
#

it's giving a syntax error on just that? maybe remove the (50) and rely on the implicit size of the bigint type

slender rose
#

hat about varchar, I need values for those

proven arrow
#

For varchar it's fine

slender rose
#

lemme try

ivory sky
#

yes, varchar has no implicit size so you always have to specify it

slender rose
#

whats the default length of bigint

#

cause user IDs can have like 20-25 characters I think

#

ahh ye it worked after I removed the length from bigint

proven arrow
slender rose
#

thanks!

#

also how do we fetch stuffs

#

cause it gives me connection object has no attribute fetchall

ivory sky
slender rose
#

think if its 19 then in some cases it might give errors cause some user ids have 20+ digits

ivory sky
#

you have that many users? šŸ˜‚

#

yeah, you may need to store your ID's as strings then

slender rose
#

o

#

no no

#

like user IDs

ivory sky
#

still use bigint for the row PK, but a second column storing the user ID as a string

#

seriously anyone designing a system with larger than 64-bit user IDs are being ridiculous

slender rose
#

oh then i'll have to convert it every time

#

ye like my user id is 513085098174709779

#

you can see that's a big ass number

#

in some cases its like 20-25 characters

#

also how do we fetch results

#

like in MySQL or SQLite we did cursor.fetchone() but that doesn't seem to work in postgres

#

and we don't even have a cursor object here

ivory sky
#

you could use the numeric type which i think under the hood just stores the value as a string but lets you treat it like a numeric type. it's as slow as storing it as a string tho.

slender rose
#

think I can just store it as a string that's less hassle

ivory sky
#

depends on which python pg client lib you're using

slender rose
#

im using asyncpg

ivory sky
#

there's probably some good answers on stackoverflow

slender rose
#

I tried looking but cant find anything

ivory sky
#

how about the docs?

proven arrow
#

Bigint is fine

proven arrow
#

You won't exceed that for discord IDs

slender rose
#

you sure?

#

idk how much postgres is different from MySQL but in MySQL discord user ID exceeded bigint in some cases

proven arrow
#

Well as far as I know all IDs are same length and under that range.

ivory sky
slender rose
#

oh I see then

#
    abc = 12345

    efg = 638287238
    await con.execute("""
                    INSERT INTO profiles VALUES ("{}", "tah", "23", "hhfh", "jfjfj2", "jfjfjfj", "jfjfjf", "jfjfjf", "jfjfjf", "jfjdjf", "jfjfjfj", "{}")""".format(abc, efg))
#

hm apparently the queries in postgres is a bit different from MySQL or SQLite I think

#

like that's giving me this

Traceback (most recent call last):
  File "abc.py", line 31, in <module>
    loop.run_until_complete(db_connection())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "abc.py", line 19, in db_connection
    toup = await con.execute("""
  File "/home/ubuntu/.local/lib/python3.8/site-packages/asyncpg/connection.py", line 295, in execute
    return await self._protocol.query(query, timeout)
  File "asyncpg/protocol/protocol.pyx", line 316, in query
asyncpg.exceptions.UndefinedColumnError: column "12345" does not exist
#

are we supposed to like mention which column something goes in? cause we didn't need to do that in MySQL or sqlite

proven arrow
#

The only time you don't specify columns is when you are inserting into every column.

slender rose
#

ohh

slender rose
#

Any idea how we fetch a specific amounts of rows in asyncpg

formal plank
#

What would be the best way (preferably free) to set up a database for a discord bot?

slender rose
#

Use sqlite?

#

There are some sites that give mysql hosting for free but I wouldn't recommend to rely on them

formal plank
#

is there anything that would work for microsoft access?

slender rose
#

I don't think so

#

I don't think you can use python/jvs to write on microsoft access db but can't be too sure

#

Maybe google it?

formal plank
#

would MongoDB work?

slender rose
#

Ye but mongodb's free tier is quiet slow

#

Queries will take up to 5 seconds to happen

#

Sometimes a bit longer

formal plank
#

the commands wont be used very often. around once a week so that should be fine

slender rose
#

Ye then ig you can use that

#

Are you gonna store a lot of data?

#

Cause if not then just use json. Json works perfectly fine if taken care properly

formal plank
#

Currently the bot is in multiple servers and one of them has 1400+ members. And i need to store data for each of them

slender rose
#

Only 1400?

#

Lmao one of my bot runs in a server with 141k users and json still works perfectly fine there

formal plank
#

ah ok lmao

slender rose
#

Unless you're handling way too many queries at a time you can stick with json

#

Just make sure to keep a backup from time to time

formal plank
#

ok thanks

sinful condor
#

@slender rose I am using mongodb free and the queries maybe take .1 seconds it is lighting fast

nocturne yew
#

psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "movies_pkey" i have a table that i already inserted two rows, then i tried to insert again, with 10 rows of value. it gives me this error. i dont want to drop the table everytime i update it, how can i set it in the insert?

#

i googled it and i found this from psycopg2.errors import UniqueViolation

#

but i am not sure, how to place it

#

cursor.execute("""INSERT INTO movies (imdb_id, imdb_id is my primary key of the table movie

torn sphinx
torn sphinx
#

what's the correct way for inserting date time in sql

smoky pendant
#

depends on database i think

#

i know mysql has a specific format of yyyy-mm-dd

neon idol
#

With Postgres you can directly insert a datetime in ISO format, as a string

smoky pendant
#

i think its the same with mysql where u encase it in a quotes. cant remember if the delimiter of - is neccessary

delicate fieldBOT
#

Hey @true kelp!

It looks like you tried to attach file type(s) that we do not allow (.zip). We currently allow the following file types: .3gp, .3g2, .avi, .bmp, .gif, .h264, .jpg, .jpeg, .mkv, .mov, .mp4, .mpeg, .mpg, .png, .tiff, .wmv, .psd, .ai, .aep, .xcf, .mp3, .wav, .ogg, .webm, .webp, .flac, .afdesign, .m4a, .csv.

Feel free to ask in #community-meta if you think this is a mistake.

true kelp
#

can i private dm somebody

torn sphinx
#

does someone know how can i use json with heroku? (i use heroku to deploy my bot)

#

or even mongoDB

scarlet cove
#

Hey I hv an doubt
Did I use and manage sqlite database online ?

uneven folio
#

Can anyone help me with json stuff here

torn sphinx
#

i installed vim but i keep getting that it's not reconized as an internal or external command
i looked for sollutions online and it told me to look in system 32 for it however even after i searched i could not find it there
it's there onto:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Vim 8.2

#

but those are fastclicker(snelkopelingen)

#

and not the actually path itself

#

adding it in the command prompt gives the same error

#

how am i suppose to solve this?

#

im following this vid

#
C:\WINDOWS\system32>c:

C:\WINDOWS\system32>..
'..' is not recognized as an internal or external command,
operable program or batch file.

C:\WINDOWS\system32>cd..

C:\Windows>cd "Program Files (x86)"
Het systeem kan het opgegeven pad niet vinden.

C:\Windows>```
#

šŸ™‚

#

Just getting into python, are guis hard to create if I wanted to start with basic IF this then that programs, to automate things with a click.

#

there are a lot of gui builders out there

#

if u use those its ez

#

What about diy for a beginner?

#

might take some time but, it do able

heavy spear
#

Wait

#

Is it about vim?

torn sphinx
#

yes

heavy spear
#

U r lucky

torn sphinx
#

well i am a rabbit after all

#

we got lucky feet

heavy spear
#

Jajajaja

#

True

#

You're using win

#

I hate win but it's okay :b

torn sphinx
#

thats fine i hate win too

heavy spear
#

Okay I like you :b

#

Look

#

Those commands that you're using are unix native if you want to move in win terminal it is different

#

I don't remember exactly what you have to use but write "help" and it will display the documentation

#

My recomendation is to use git bash terminal

#

It's a little bit better

#

Next

#

Try v -v

#

Or vim -v

#

Or vim --version

#

To check if vim was well installed

torn sphinx
#

okay i did but it cannot find vim

#

even after i installed it

heavy spear
#

Well

#

It means that it's not installed

torn sphinx
#

then how can i run the program?

heavy spear
#

Let me see the documentation and then I will come back :b

#

Well If you're live vim (Like me)

torn sphinx
#

no i mean i installed it and it runs

heavy spear
#

You can use VS Code with vim extension if you need it asap

torn sphinx
#

yes i am using VS Code

heavy spear
#

I misunderstood xd

torn sphinx
#

C:\Windows>vim --version
'vim' is not recognized as an internal or external command,
operable program or batch file.

#

and yet

torn sphinx
heavy spear
#

Sorry xd

#

Let me check

torn sphinx
#

no no im glad u are trying to help

heavy spear
#

Come on

#

You're a bunny

#

I have to

#

Xd

torn sphinx
#

true we are made to be loved

heavy spear
#

Is it win7 or win10?

torn sphinx
#

win10

heavy spear
#

Exactly

#

Witch one?

#

Home, pro, etc

torn sphinx
#

home

heavy spear
#

64x

#

I suppose

torn sphinx
#

yes 64 bit

heavy spear
#

Got it

#

Well

#

I found something

#

Uninstall vim and remove the dir, then reinstall it and check the VimX file

torn sphinx
#

can do

heavy spear
heavy spear
heavy spear
#

I think that it better to download this installer

torn sphinx
#

yep

#

it works

#

i had it set to partly install

#

Step 2: Now open the setup file and follow the on-screen instructions. In the step where the setup asks you for the installation type, select Full and hit next.

#

when i followed that one

#

it worked

#

@heavy spear thanks so much ā¤ļø

heavy spear
#

Ohhhhhh cool XD

#

I'll be lucky :b

#

I don't know if you have your .vim

faint ibex
#

anyone know how input variables in python into SQL flask statements
def something(username):
con.execute('SELECT * FROM store Where Shopname = :name', {'name':username})

#

would give a syntax error, not quite sure how to input the values from 'username' into the sql statement

marble osprey
#

i am trying to make the ave function here work

#

and i cant quite figure it out

lime tide
proven harness
#

there's a module you can use to deal with excel

#

openpyxl

#

you can find it on pypi

frank thistle
#

any solution????

#

defaulting to user installation because normal site-packages is not writable

proven harness
#

I think it means you already installed the module

frank thistle
#

why it is showing this

proven harness
#

I don't know about that

#

sorry

frank thistle
#

it never happened before but after this i am unable to use any of the other modules

bleak crown
#

Hi i'm using aiosqlite and i'm trying to update something to my database but i want to raise error if that thing doesn't exist in there

#

But UPDATE method doesn't raise error

#

But UPDATE returned an aiosqlite object, can i use it and take the information that i want from there?

proven arrow
#

@bleak crown the execute function on update will return a cursor object. This will have a rowcount attribute that tells you how many rows were affected by the update.

#

You can check if it's 0, which would mean it didn't update anything

bleak crown
#

Yeah, thank you ā¤ļø

torn sphinx
#

Can anyone help me with motor async?

#

(Mongo db)

burnt turret
#

Ask your question, someone will answer if they can

dusk junco
#

How can I migrate a Postgres database hosted on my localhost to a Docker image? My goal is, of course, that another collaborator can access the database in its remote machine

neon idol
#

@dusk junco You case use the official Postgres docker image, which works very well

dusk junco
neon idol
#

you can use pg_dump and pg_restore to transfer you data

#

a docker container is based on a particular image

dusk junco
#

I've done this simple docker-compose but I don't know if it will work

version: '3' 
services:
  postgres:
    image: docker_image
    container_name: python:3.7.9-stretch
    ports:
      - "5432:5432"
    network_mode: host
    environment:
      - LC_ALL=C.UTF-8
      - POSTGRES_DB=elevation
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=
      - POSTGRES_PORT=5432
neon idol
#

you can understand a container as being an "instance" of an image

neon idol
#

if you wanted to use the official PG docker image, your image field should be something like postgres:latest

dusk junco
#

Ok, right. I'll give it a try then

#

Thanks @neon idol

neon idol
#

if you have other questions about it don't hesitate to ping me!

hollow abyss
#

database guyes hello XD

#

facing a weird problem with mongo

#

what does this mean and how to fix it?

burnt turret
#

show the code that is raising this

torn sphinx
#

can someone help me

#

how can i update a colum in mysql.connecotr

#
sql_query = (f"UPDATE hikari_clients SET plan = {arg1} WHERE client_id = {client_id}")
safe robin
#

If you are inserting values into a table (assume using SQL, I'm very new to this), and you have defined a field to have a default value, how do you "skip" having to write NULL in that field if you don't have the value yet. An example is that you have 3 fields and the last field is called bird_example and contains BLOBs. I don't have the BLOB yet, but want to insert data for the first two fields, id and bird_name. I tried to just write "INSERT INTO birds VALUES (1, 'Hummingbird', NULL [I want to skip this blob] ) ;".

EDIT: I found out that you can specify which columns you want to input values for, so I just skipped the BLOB field :D.

torn sphinx
#

Hi, does anyone now how environment variable work in python? I have a .env file with all the relevant information (e.g USER=postgres) and in my main python file I have imported dotenv. If I don't use environment variables I can connect to my database and insert data but when I use environment variables I get the following error:

psycopg2.errors.UndefinedTable: relation "my_table" does not exist

My envrionment variables look like this:

            host = os.getenv('HOST'),
            dbname = os.getenv('DBNAME'),
            user = os.getenv('USER'),
            password = os.getenv('PASSWORD'),
            port = os.getenv('PORT')

Any help would be amazing!

wet mesa
#

Just to check, you are loading the env variables?

torn sphinx
#

I want to load them but I am doing something wrong as they dont appear to be read by the code, like I said when I don't use env variables the data is inserted into the db but when I do use them it says the table does not exist

wet mesa
#

What I mean is, do you have this before trying to access env variables?

from dotenv import load_dotenv
load_dotenv()
torn sphinx
#

ah yeah i see, just under it as you said

burnt turret
#
await self.bot.db_pool.fetch("SELECT note_id, raw_note FROM notes WHERE user_id=$1 AND note_id IN ($2::array)", ctx.author.id, note_id)

the variable note_id is a python list of integers, how would i use the sql IN operator here? this is asyncpg + postgresql (ping me on response please)

burnt turret
#

you're directly trying to insert the discord.Member object by the looks of it

#

insert only the user's ID

#

moreover, the code you just showed doesn't show the related code for the error

ebon skiff
#

@burnt turret I've fixed it! Should have read it more carefully i have now made python convert it and not let mysql trying to do it.

golden warren
#

Hello their! I have this code:

            # Fetch all member name / id
            guild = self.client.get_guild(Guild.id)
            guild = await guild.chunk()
            for member in guild:
                print(member)
                self.usersdb_cursor.execute(
                    'INSERT OR IGNORE INTO user(user_id, user_name, user_discriminator, user_creation) VALUES(?, ?, ?, ?)', (member.id, member.name, member.discriminator, member.created_at))
            self.logger.log('information', 'Fetch all data from users.')

But it doesn't right anything in my db but, when i print(member) i list all user. Have you got idea?

bitter yoke
#

Is that SQLite?

#

In any case, you may just need to call commit() on the connection

#

Depends on how you set it all up, though.

#

(Commit at the end, at least, that is -- in your case you could do it either after each execute inside the loop, or just when the loop is done and all the inserts were executed.)

golden warren
#

@bitter yoke Yes.

#

Okay thx it work!

bitter yoke
#

Yay! šŸ•ŗ

golden warren
#

@bitter yoke Do you why it doing that:

[2021-01-18 21:33:53] Error: 'NoneType' object has no attribute 'execute'

Code:

class DB:
    def __init__(self, client):
        self.client = client
        self.logger = Logger()
        self.usersdb = None
        self.usersdb_cursor = None

    async def initialization(self):
        try:
            # Connection to database.
            self.usersdb = sqlite3.connect('src\\db\\users.db')
            self.usersdb_cursor = self.usersdb.cursor()
            self.logger.log('sucess', 'Connected on db.')

            # Create table
            self.usersdb_cursor.execute(
                'CREATE TABLE IF NOT EXISTS user(user_id INTEGER NOT NULL UNIQUE, user_name STRING NOT NULL, user_discriminator STRING NOT NULL, user_creation)')
            self.usersdb_cursor.execute(
                'CREATE TABLE IF NOT EXISTS infraction(id INTEGER NOT NULL, user_name STRING NOT NULL, user_id INTEGER NOT NULL, moderator_name STRING NOT NULL, moderator_id INTEGER NOT NULL, reason STRING, infranction_number INTEGER NOT NULL)')
            self.logger.log(
                'sucess', 'Table creation was successfull create in usersdb.')

            # Fetch all member name / id
            guild = self.client.get_guild(Guild.id)
            guild = await guild.chunk()
            for member in guild:
                self.usersdb_cursor.execute(
                    'INSERT OR IGNORE INTO user(user_id, user_name, user_discriminator, user_creation) VALUES(?, ?, ?, ?)', (member.id, member.name, member.discriminator, member.created_at))
                self.usersdb.commit()
            self.logger.log('information', 'Fetch all data from users.')
        except Exception as e:
            self.logger.log('error', e)
bitter yoke
#

nope but i can take a guess in a sec if you haven't found it

golden warren
bitter yoke
#

so you know which line it's complaining about though, yeah?

golden warren
#

Nop, i don't know :(

#

I don't see what is wrong :(

bitter yoke
#

so when it complains that it can't find "execute" it's gonna be complaining about a line where you try to use something called execute

#

and I see... I think that narrows it down to 1 line in that code right?

golden warren
#

Yes

autumn epoch
#

Im kinda stupid but what is this type of variable called?

var = {
  code
}
golden warren
#

It's say that i can execute with none :(

bitter yoke
#

@golden warren so when it says it can't find "execute" in NoneType it's saying that self.usersdb_cursor is None

#

so it's trying to do

#

None.execute()

#

and that doesn'twork

golden warren
#

Yes.

bitter yoke
#

@autumn epoch is "code" a bunch of this: "That", you: "me", potato: "potato" in that example?

autumn epoch
#

Yes

bitter yoke
#

that's a dictionary

autumn epoch
#

Ok thank you

bitter yoke
#

yup

#

other languages call it a hash or other such thing

proven arrow
golden warren
#

At begin, it started but when a user join discord server i think that connection is non @bitter yoke

#

'NoneType' object has no attribute 'execute

autumn epoch
#

Also how would I have a variable in a dictionary. Like Name: Name

bitter yoke
#

so we have

torn sphinx
#

im looking for a very fast database which can store a huge amout of links,products and access it. Is mysql good enough?

bitter yoke
#
name = "Jimmy"
 x = {
    "name": name,
    "age": 6
}
#

like that?

torn sphinx
bitter yoke
#

yep

#
In [7]: x['name']
Out[7]: 'Jimmy'

In [8]: x['age']
Out[8]: 6

autumn epoch
#

Like this:

new_player = {
"The players name": {
          "xp": 1,
          "level": 0
       }
}
bitter yoke
#

jimmy's just a little tyke

#

ah so in that example

autumn epoch
#

Yes

#

That is exactly what I am trying to do

bitter yoke
#

without knowing your goal

#

The left side of the : is the 'key' and the right side is the 'value'

#

so "width": 5

autumn epoch
#

Yes

bitter yoke
#

and "height": 8

#

but

#

"Jimmy":

#

isn't the same as "width" and "height" if you see -- it's not the name of a thing about jimmy

#

so "Jimmy": ....

#

"what is the value of my width" and "what is the value of my height" make sense

#

but let's not talk about "what is the value of my jimmy"

#

but you can do what you're talking about, and it's pretty hard to say whether it's right or wrong without knowing what you're making this dictionary to do

autumn epoch
#

Its to store information about the player, xp, level, inventory

#

So the program can access it later

#

And also it is saved to a json file

bitter yoke
#

that makes sense, but to decide what the keys are

#

is this one big json file of all players, or a file-per-player?

autumn epoch
#

One big one for all the players

bitter yoke
#

and when you load the file, do you know what kind of python data you want from it? a list of players? or, I'm sensing, maybe you want a big dictionary where you can say all_players['jimmy'] and get jimmy's data?

autumn epoch
#

Well using the discord.py I am going to wait till someone chats, checks if their name is on the file and then change the stats

proven arrow
#

Considering json is not for mutable data storage you should try and avoid it for what you are trying to do.

#

Would be better to use a relational db

autumn epoch
proven arrow
#

It can very quickly become a pain to manage, and querying the data would be much easier with sql as well. And since you mention discord.py JSON would also be blocking whenever you read/write to it.

autumn epoch
#

It was working for me at the moment

#

No problems at all

proven arrow
#

Well you may not notice it since if your testing, with only a few users.

bitter yoke
#

you could make it work with a json file but you will not be happy with it, because you want the real-time updates

#

right

autumn epoch
#

Wdym it is getting real time updates

bitter yoke
#

right but getting real-time updates from multiple users into a single disk file is not a problem you want to solve by hand

autumn epoch
#

I text look at the file and it updated

#

Oh

proven arrow
#

However since discord code would be async, each time you write/read from the file your bot would become unresponsive for how long it takes to read/write from the file. As i said you might not notice it now but when you have many users at once you will.

bitter yoke
#

like what if two users log in "at once" etc

#

right

#

it'll "work"

autumn epoch
#

So what would work?

bitter yoke
#

and i've done that kind of thing for something I knew would never have more than 2-3 users

#

but it still kinda sucked

#

@autumn epoch can you re-state the problem you're really trying to solve? I think I may have lost the point here

autumn epoch
#

Yes

bitter yoke
#

thx

autumn epoch
#

So basically when a new player joins, it would add on to the file, but I need the players name, which is in a variable

bitter yoke
#

so let me fake it here:

autumn epoch
#

Ok

bitter yoke
#

so here are two things, in variables:

In [12]: new_player = "another player"

In [13]: print(new_player)
another player

In [14]: x = 5

In [15]: print(x)
5
#

and if i want them in a dictionary I can do

#
In [17]: player = {
    ...:    "name": new_player,
    ...:    "size": x
    ...: }

In [18]: player
Out[18]: {'name': 'another player', 'size': 5}

#

so the fact that they're variables isn't a big deal, like where I said 'x' I could've said '5'

#

same thing

#

so that's the syntax for using variables to set things in a dictionary

autumn epoch
#

Ok thank you

bitter yoke
#

sure

#

if that's not the thing, I'll be back later

#

gl

autumn epoch
#

Thx

pure dirge
#

Need help with high data @ me pls

smoky pendant
#

any tips on choosing databases? Ive got report data to store and the different types have different fields. Should i go with non relational or relational. I mean i could shove it all into a json like format with mongo but is having definitive structure better?

torn sphinx
#

Depends on what your requirements are. Different databases are good at different things, so define your requirements first and then go from there.

smoky pendant
#

yeah im prob gonna have to ask tmr

burnt turret
spice scarab
#
ConfigurationError: The "dnspython" module must be installed to use mongodb+srv:// URIs```
can i get help with this? im trying to use my mongodb and i keep getting this error, ive installed pymongo[srv] and imported dns, but still getting the same error.
#

somehow, rebooting the bot fixed it..??? i dont know how since i was reloading and trying to load it again

burnt turret
fiery bone
#

hi!

#

Does a mysql server need anything to accept connections from python

burnt turret
#

If I have a bunch of dates in my postgres database, how can i get back all the rows in which the day-month is the same as today's day-month? the year can be different, but i want the rows with the same day and month. (i'm not sure if i've explained the question well enough, i can try rephrasing)

proven arrow
#

For example, for date in the where you can have WHERE extract(day FROM your_date_col) = extract(day FROM current_date);

burnt turret
#

@proven arrow what is the difference between this extract function and date_part?