-
-
Notifications
You must be signed in to change notification settings - Fork 362
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
Add columns.list
function
#3556
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great overall, I've requested some minor changes.
from mathesar.utils.columns import get_raw_display_options | ||
|
||
|
||
class TypeOptions(TypedDict, total=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the total
flag for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, setting it to False
is an explicit flag to let the reader know that not all fields of the dictionary are required. It's not enforced in any way (except by linters).
Args: | ||
db_id: The Django id corresponding to the Database. | ||
""" | ||
print("User is: ", user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You missed a print
statement here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually left that on purpose for the moment. My thinking is that this function body is going to be replaced once we have the permissions stuff worked out. For now, I'd like to leave that as a placeholder for logic that will use the user
to get a connection credential.
def get_psycopg_connection(db_model): | ||
""" | ||
Get a psycopg connection, given a Database model. | ||
|
||
Args: | ||
db_model: The Django model corresponding to the Database. | ||
""" | ||
return psycopg.connect( | ||
host=db_model.host, | ||
port=db_model.port, | ||
dbname=db_model.db_name, | ||
user=db_model.username, | ||
password=db_model.password, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not have this in connect()
itself? I thought we discussed that we'd always need to call connect
with appropriate arguments and won't be opening random connections elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For any user request, this is true. However, we have a few things (installation, upgrade) that won't have a user associated with them. I wanted to leave this function available for those use cases.
WHEN 1 << 2 THEN 'year' | ||
WHEN 1 << 1 THEN 'month' | ||
WHEN 1 << 3 THEN 'day' | ||
WHEN 1 << 10 THEN 'hour' | ||
WHEN 1 << 11 THEN 'minute' | ||
WHEN 1 << 12 THEN 'second' | ||
WHEN (1 << 2) | (1 << 1) THEN 'year to month' | ||
WHEN (1 << 3) | (1 << 10) THEN 'day to hour' | ||
WHEN (1 << 3) | (1 << 10) | (1 << 11) THEN 'day to minute' | ||
WHEN (1 << 3) | (1 << 10) | (1 << 11) | (1 << 12) THEN 'day to second' | ||
WHEN (1 << 10) | (1 << 11) THEN 'hour to minute' | ||
WHEN (1 << 10) | (1 << 11) | (1 << 12) THEN 'hour to second' | ||
WHEN (1 << 11) | (1 << 12) THEN 'minute to second' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is amazing!!!
from mathesar.models.users import User | ||
|
||
|
||
def test_columns_list(rf, monkeypatch): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a docstring for the fixtures used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I'll add a docstring at the top of the file. I think that's going to be better in general, since fixtures are defined in such a way that they're file-wide and not restricted to any given test function.
Okay, I think I've addressed everything, @Anish9901 . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Fixes #3549
Fixes #3571
This adds an RPC function called
columns.list
that takes adatabase_id
andtable_oid
as input, and returns information about the columns of the identified table.Technical details
pgTAP
setup function feature, since that bogs the tests down too much.mathesar.rpc.columns.list_
is kept pretty simple. It's responsible for getting a connection using the provided utility function, and then calls other functions to actually gather data.mathesar.rpc.columns.list_
doesn't directly use the connection to access the database, but it does call the db access function within a managed context.mathesar.utils.columns.get_raw_display_options
is a bit of scaffolding for now, since the new model hasn't been made yet.database_id
anduser
mathesar.rpc.utils.connect
function is also a stub for now, but its signature should also stay the same.mathesar.tests.rpc.test_endpoints
tests that the expected functions are shown, at that each is defined with the expected decorators are applied. Nothing more.Checklist
Update index.md
).develop
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin