@ponyorm

Страница 17 из 75
Luckydonald
16.01.2017
14:09:45
I guess that would download the files before, I mean I need to get all the python dependencies too, so thats not that problematic to add a extra step there

Romet
16.01.2017
14:39:31
@micaiahparker In the company I work at, we publish the project template we use internally for pretty much everything.

https://github.com/thorgate/django-project-template

Might be interesting

Google
Марк ☢
16.01.2017
19:49:35
https://github.com/pythonql/pythonql

Pony-like thing

Alexander
16.01.2017
21:34:14
Looks interesting. But this is not a standard Python

stsouko
17.01.2017
14:38:54
Hello! Is it possible working with multiple db with cross-links?

e.g. user table in db1 and posts in db2?

Alexander
17.01.2017
14:42:33
Yes, but you need to process foreign keys manually: class User(db1.Entity): name = Required(str) class Post(db2.Entity): user_id = Required(int) title = Required(str) content = Required(str) ... with db_session: u1 = User.get(name='John') posts = select(p for p in Post if p.user_id == u1.id)

stsouko
17.01.2017
14:44:14
ok! Thank you.

q2. Can I use Sets bw 2 db?

Alexander
17.01.2017
14:46:58
No, but maybe it is not hard to do an equivalent operation without using Sets

stsouko
17.01.2017
14:47:09
https://github.com/stsouko/predictor

I try to implement project for online predictions of chemical properties and data store

this is my db model: https://github.com/stsouko/predictor/blob/master/MWUI/models.py

I want to combine 3 db

Google
stsouko
17.01.2017
14:49:59
A way for replace set is to implement property with select query?

class Users(db_main.Entity): id = PrimaryKey(int, auto=True) active = Required(bool, default=True) email = Required(str, unique=True) password = Required(str) user_role = Required(int) tasks = Set('Tasks') token = Required(str) restore = Optional(str)

Alexander
17.01.2017
14:50:32
Why do you want to split data between several databases?

Luckydonald
17.01.2017
14:51:20
Probably because they already are?

stsouko
17.01.2017
14:51:22
db_data is db for storing train set data

db_pred is users saved predictions.

db_main store only articles for web-site

Alexander
17.01.2017
14:53:40
What database do you use?

stsouko
17.01.2017
14:53:46
postgres

data for train can be used separately

Alexander
17.01.2017
14:55:40
I think yes, you can define property with select inside to emulate Set across different database. Or just use select directly, like in the example I wrote with users and posts

stsouko
17.01.2017
14:57:55
Ok. Thank You! property is more clear.

I think

Alexander
17.01.2017
15:05:16
If I remember correctly, in PostgreSQL a server is called "database" and a database is called "schema". You can have three different schemata inside the same physial server. In that case, you can use normal Sets between schemata. In order to do this, you need to specify table names manually, as a list or a tuple of two components: schema name and table name. For example: db = Database() # common db object for all schemata class User(db.Entity): _table_ = ['db_main', 'users'] tasks = Set("Task") ... class Task(db.Entity): _table_ = ['db_pred', 'tasks'] user = Required("User") ... By the way, it is better to name entities in a singular form: User instead of Users, etc.

Святослав
17.01.2017
15:12:20
Hi. How i can create unique index for column by clause UPPER(column)?

stsouko
17.01.2017
15:13:15
In this recipe how to create tables in db? Manually or pony can?

Alexander
17.01.2017
15:15:47
In this recipe how to create tables in db? Manually or pony can?
If you create three empty schemata inside a single postgresql server, and specify two-element _table_ name for each entity, Pony should be able to create all tables automatically

Hi. How i can create unique index for column by clause UPPER(column)?
You can add this manually by executing corresponding CREATE INDEX command. When we release migrations it will be possible to put this code inside custom migration

stsouko
17.01.2017
15:17:12
Thank you very much!

Alexander
17.01.2017
15:17:22
Sure

Google
Святослав
17.01.2017
15:18:27
Why not allow use raw_sql expressions for indexes? This way to got overloaded entity model in Python?

Alexander
17.01.2017
15:19:56
It's a good idea, we probably can implement it. You can open a corresponding issue. I think it may take some time to implement, because other tasks (like migrations or new JSON serialization API) right now have a bigger priority

Luckydonald
17.01.2017
15:30:31
Postgres has a plugin to have a select over multible databases (&hosts)

Hey a new stickerpack. The 2859th I came across.

Alexander
17.01.2017
15:44:32
That's cool

Luckydonald
17.01.2017
15:45:54
Flagging NSFW stickers is a lot of work :(

Anyone has experience with all that social stuff? Currently it is only crawling and displaying, but I want to add some user experience, like voting and stuff

Micaiah
17.01.2017
15:55:00
For 'Recently Used' you could probably get away with a displaying them in a grid and then adding the emoji, open button, and flag button to the bottom of each sticker image

Micaiah
17.01.2017
15:56:04
Also you might want to display page+1 so that users first page is page 1

Luckydonald
17.01.2017
15:56:31
The discovering process is funny, I need to use a regular Telegram client to look up the sticker pack, the Telegram Bot API doesn't feature that :S

Micaiah
17.01.2017
15:58:54
Wow, you should request that haha

Luckydonald
17.01.2017
16:01:35
To summarize how it works:

Micaiah
17.01.2017
16:05:45
what would an example query look like

Luckydonald
17.01.2017
16:05:58
Always fun when the API blocks me for 86000 seconds (~23:40 hours).

Micaiah
17.01.2017
16:06:37
Oh I guess I was trying to use it wrong

Like, if I was in a convo and I wanted to use @StickerTagBot to send a sticker to that person

Although you might want to add limits to prevent getting blocked like that haha

Google
Luckydonald
17.01.2017
16:08:42
Like, if I was in a convo and I wanted to use @StickerTagBot to send a sticker to that person
Problem is currently, that the Database is too slow to answer telegram in times, so I basically get "Error: you are to slow" back when trying the inline query.

Micaiah
17.01.2017
16:09:06
Oh

Would it be faster if you swapped out Flask for something faster? I hear Sanic (however stupid the name) is freaaaky fast

And its async which sounds good for something like this

Luckydonald
17.01.2017
16:11:26
Oh, never mind, I killed the query somehow. TypeError: Function 'startswith' cannot be used this way: query_text_lower.startswith(p_t.string.lower())

Micaiah
17.01.2017
16:11:50
Hmm

Alexander
17.01.2017
16:13:39
Shouldn't it be the other way around? p_t.string.lower().startswith(query_text_lower)?

Alexander
17.01.2017
16:16:36
By the way, do you currently have index on lower(p_t.string)?

Luckydonald
17.01.2017
16:16:41
I was thinking about deploying a elasticsearch instance to make that string based querying faster, and also get a relevance factor but keeping the data in sync is a problem of it's own.

By the way, do you currently have index on lower(p_t.string)?
Following the article linked above, I uses CREATE INDEX customer_names_on_last_name_idx ON customer_names USING GIN(last_name gin_trgm_ops);

To be specific: -- http://blog.scoutapp.com/articles/2016/07/12/how-to-make-text-searches-in-postgresql-faster-with-trigram-similarity CREATE EXTENSION IF NOT EXISTS pg_trgm; -- index on tag.string CREATE INDEX IF NOT EXISTS tag_string_trigram_idx ON tag USING GIN(string gin_trgm_ops);

Article says, it is case insensitive anyway, so that's not a problem

Indeed, it was not timeouting, but the query was wrong.

Micaiah
17.01.2017
16:23:34
Thats better

Luckydonald
17.01.2017
16:30:14
I thought I had the PonyORM sticker in my database as well

This one

Alexey
17.01.2017
16:31:57
You should) But may be you can add ponyorm.com under it?

What do you think?

Google
Luckydonald
17.01.2017
16:37:18
How can I use ILIKE?

Alexander
17.01.2017
16:37:40
You can write raw sql fragment

something like and raw_sql('table_name.column_name ILIKE $(python_expr)')

Luckydonald
17.01.2017
16:40:12
There is nothing built-in?

Alexander
17.01.2017
16:40:56
Python does not have equivalent operation, I think it should be easy to write raw sql fragment inside a generator query

Luckydonald
17.01.2017
16:43:04
My current line with that is orm.exists(p_t for p_t in st.sticker.sticker_pack.tags if query_text_lower in p_t.string) I was thinking there could be a modifyer like orm.desc(...) Like orm.ignorecase(query_text_lower in p_t.string) or query_text_lower in orm.ignorecase(p_t.string)

Alexander
17.01.2017
16:50:52
Curretly we don't support such modifiers. You can process escapes manually outside of a query: like_template = '%' + query_string.replace('!', '!!').replace('%', '!%').replace('_', '!_') + '%' select(p_t for p_t in st.sticker.sticker_pack.tags if raw_sql("p_t.string ILIKE $like_template ESCAPE '!'"))

Luckydonald
17.01.2017
16:52:38
Maybe I can modify my index to have LOWER(string) instead of string: CREATE INDEX IF NOT EXISTS tag_string_trigram_idx ON tag USING GIN(LOWER(string) gin_trgm_ops); And just query query_string.lower() in p_t.string.lower() instead of query_string in p_t.string

Alexander
17.01.2017
16:53:25
Yes, it is possible as well

Luckydonald
17.01.2017
16:53:38
I'll try that, not sure if the index part will work

Curretly we don't support such modifiers. You can process escapes manually outside of a query: like_template = '%' + query_string.replace('!', '!!').replace('%', '!%').replace('_', '!_') + '%' select(p_t for p_t in st.sticker.sticker_pack.tags if raw_sql("p_t.string ILIKE $like_template ESCAPE '!'"))
With the raw_sql I always am missing the options to include the parameters I want as actual arguments, like "{} {}".format(arg1, arg2) which feels safer to sql injection and also IDE's won't mark variables as unused.

Alexander
17.01.2017
17:00:34
When you use $expr inside raw_sql it should convert it to actual parameter. About IDEs, maybe we need to allow to explicitly pass variables to raw_sql, like in python_expr = 'hello' raw_sql("column ILIKE $expr", expr=python_expr)

Страница 17 из 75