Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres querybuilder #315

Closed
egwald opened this issue Jan 20, 2021 · 5 comments · Fixed by #316
Closed

Postgres querybuilder #315

egwald opened this issue Jan 20, 2021 · 5 comments · Fixed by #316
Labels
bug An existing feature is not working as intended Grammar These issues relate to the Grammar portion of the codebase

Comments

@egwald
Copy link

egwald commented Jan 20, 2021

Hi, I use masonite3 with the new ORM with PostgreSQL 13.1 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.3.0) 9.3.0, 64-bit.
Now I try:

 builder = QueryBuilder().table('information_schema.columns')
   md = builder.select('table_name', 'column_name', 'is_nullable', 'data_type', 'character_maximum_length').where('table_name', 'users').order_by('column_name', 'desc').get()

and the I have the error:

#1 ..lNG/venv/lib/python3.9/site-packages/masoniteorm/connections/PostgresConnection.py:162
if "SELECT" in cursor.statusmessage:
return cursor.fetchall()
return {}
except Exception as e:
raise QueryException(str(e)) from e
finally:
if self.get_transaction_level() <= 0:
self.open = 0
self._connection.close()
')
Python

self <masoniteorm.connections.PostgresConnection.PostgresConnection object at 0x7f3097829be0>
query 'SELECT "information_schema.columns"."table_name", "information_schema.columns"."column_name", "information_schema.columns"."is_nullable", "information_schema.columns"."data_type",
"information_schema.columns"."character_maximum_length" FROM "information_schema.columns" WHERE "information_schema.columns"."table_name" = %s ORDER BY "information_schema.columns"."column_name" DESC'
bindings ('users',)
results '*'
RealDictCursor <class 'psycopg2.extras.RealDictCursor'>
cursor <cursor object at 0x7f309a66de40; closed: -1>

QueryException('relation "information_schema.columns" does not exist\nLINE 1: ...n_schema.columns"."character_maximum_length" FROM "informati...\n ^\n')

Can you help me?

This works fine:

SELECT information_schema.columns."table_name",
	information_schema.columns."column_name",
	information_schema.columns."is_nullable",
	information_schema.columns."data_type",
	information_schema.columns."character_maximum_length"
FROM information_schema.columns
WHERE information_schema.columns."table_name" = 'users'
ORDER BY information_schema.columns."column_name" DESC
@josephmancuso
Copy link
Member

Looks like the issue is that it is compiling as "information_schema.columns"."table_name" when it should be information_schema.columns."table_name"

@josephmancuso josephmancuso added bug An existing feature is not working as intended Grammar These issues relate to the Grammar portion of the codebase labels Jan 20, 2021
@josephmancuso
Copy link
Member

Should just be a fix inside the PostgresGrammar class I think.

@josephmancuso
Copy link
Member

@girardinsamuel thoughts?

@Marlysson
Copy link
Contributor

Marlysson commented Jan 20, 2021

@josephmancuso I've searched in QueryBuilder class and I didn't found... Shouldn't we implement in which schema the table should be applied? like:

qb = QueryBuilder(schema="information_schema").table("columns")

or should we split the content ( "information_schema.tables" ) by dot and apply into select_format method..

@josephmancuso
Copy link
Member

@egwald this is fixed in version 1.0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended Grammar These issues relate to the Grammar portion of the codebase
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants