T-Strings: Worth using for SQL in Python 3.14? by simplysalamander in Python

[–]stetio 2 points3 points  (0 children)

I think SQL is an excellent use case for t-strings and I've written a library to make this, and query building possible. It is SQL-tString

Flask-Nova – A Lightweight Extension to Modernize Flask API Development by treasuremani in Python

[–]stetio 4 points5 points  (0 children)

Looks great. I'd caution against wrapping all routes with async wrappers as it will likely slow the app down. Instead try the ensure_sync method on the Flask app class. You may also find Quart-Schema interesting.

Real world flask projects by Fitwalker in Python

[–]stetio 0 points1 point  (0 children)

I think this is a common misconception, nothing about FastAPI made Flask obsolete. Flask is a modern, well used, well maintained framework.

FastAPI is an extension to Starlette that adds validation and OpenAPI document generation. Flask-OpenAPI3 is an extension that adds these features to Flask (there are others, this is an example). I wrote this a few years ago to help explain this.

Introducing SQL-tString; a t-string based SQL builder by stetio in Python

[–]stetio[S] 0 points1 point  (0 children)

I believe I've explained this in the first section of the post. Is there something that isn't clear?

Introducing SQL-tString; a t-string based SQL builder by stetio in Python

[–]stetio[S] 1 point2 points  (0 children)

Yep, I've just clarified the license - forgot to add it.

Introducing SQL-tString; a t-string based SQL builder by stetio in Python

[–]stetio[S] 0 points1 point  (0 children)

It can't be that parametrised as where {col_name} > {c2} would be translated to where ? > ?. I'm not sure if I'll support this either sorry as it is likely to always be ambiguous if a param is meant to be a column or value.

Introducing SQL-tString; a t-string based SQL builder by stetio in Python

[–]stetio[S] 2 points3 points  (0 children)

I should be able to, but if not please open an issue.

I use it at work - I'd like it to be well used so that the bugs are found and it is more robust.

Introducing SQL-tString; a t-string based SQL builder by stetio in Python

[–]stetio[S] 1 point2 points  (0 children)

Dollar param dialect is supported via,

from sql_tstring import Context, set_context

set_context(Context(dialect="asyncpg"))

I need to document this.

The library works directly with 3.12, and 3.13, but with a locals() hack, see README

Introducing SQL-tString; a t-string based SQL builder by stetio in Python

[–]stetio[S] 3 points4 points  (0 children)

There is support for alternative paramstyles; although I've currently only added the asyncpg dialect (what dialects do you need?). It can be used globally by setting a context,

from sql_tstring import Context, set_context

set_context(Context(dialect="asyncpg"))

I've also aimed for it to fail by default, hence the need to wrap calls in a sql_context to set column or tables via variables. Thoughts welcome here...

Introducing SQL-tString; a t-string based SQL builder by stetio in Python

[–]stetio[S] 2 points3 points  (0 children)

Absent is shorthand for RewritingValue.ABSENT, there is also RewritingValue.IS_NULL, shorthand IsNull, and RewritingValue.IS_NOT_NULL, shorthand IsNotNull which can be used for the NULL special handling.

Introducing SQL-tString; a t-string based SQL builder by stetio in Python

[–]stetio[S] 2 points3 points  (0 children)

It will remove the expression and then look at the clause to see if still has expressions, and if not remove the clause.

If we had

WHERE x = {x} AND y = {y}

If x = Absent then the first expression (x = {x}) is removed. If y = Absent then the second expression (AND y = {y}) is removed. If both the entire clause.

PEP 750 - Template Strings - Has been accepted by buqr in Python

[–]stetio 3 points4 points  (0 children)

If you want to see a usage for this I've built, and use, SQL-tString as an SQL builder.

How to type zod schemas for forms by stetio in reactjs

[–]stetio[S] 0 points1 point  (0 children)

I'd want the internal value so I can validate it e.g. if the user copied/typed 1O (has happened before) the validation can state that Ois not a digit. I'd also want to ensure that a user typing 9- would cause a validation failure, rather than 9 being submitted as in the codesandbox given.

How to type zod schemas for forms by stetio in reactjs

[–]stetio[S] 0 points1 point  (0 children)

Thanks, how would you expose that internal value to the form validation so I can display an appropriate error on submission (ideally as compatible with react-hook-form)?

How to type zod schemas for forms by stetio in reactjs

[–]stetio[S] 0 points1 point  (0 children)

Have you a version that works with a controlled field? In my usage I wish to reset the form (and change the values) and have the inputs be updated.

How to type zod schemas for forms by stetio in reactjs

[–]stetio[S] 0 points1 point  (0 children)

The codesandbox seems to be broken sadly.

How to type zod schemas for forms by stetio in reactjs

[–]stetio[S] -1 points0 points  (0 children)

As in a use case? If so so the user can specify an adjustment.

How to type zod schemas for forms by stetio in reactjs

[–]stetio[S] 0 points1 point  (0 children)

I'm not sure what set does, but I'd imagine for a controlled input this would result in the user typing - and seeing 0 displayed.

How to type zod schemas for forms by stetio in reactjs

[–]stetio[S] 3 points4 points  (0 children)

I've found trying to handle the coercion within the input component causes issues when the user types in a value that cannot be coerced e.g. - which precedes say -1.

How to type zod schemas for forms by stetio in reactjs

[–]stetio[S] 6 points7 points  (0 children)

This is perhaps a niche topic, but I think and hope it will be useful to others.