-
-
Notifications
You must be signed in to change notification settings - Fork 317
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
Implement tables.add
rpc endpoint
#3614
Changes from all commits
d922f49
88b8e20
fe7b73a
5945d65
4234b01
fe0835b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,8 @@ To use an RPC function: | |
options: | ||
members: | ||
- list_ | ||
- get_ | ||
- get | ||
- add | ||
- delete | ||
- TableInfo | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
""" | ||
Classes and functions exposed to the RPC endpoint for managing table constraints. | ||
""" | ||
from typing import TypedDict | ||
|
||
|
||
class CreateableConstraintInfo(TypedDict): | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ | |
|
||
from db.tables.operations.select import get_table_info, get_table | ||
from db.tables.operations.drop import drop_table_from_database | ||
from db.tables.operations.create import create_table_on_database | ||
from mathesar.rpc.columns import CreateableColumnInfo | ||
from mathesar.rpc.constraints import CreateableConstraintInfo | ||
from mathesar.rpc.exceptions.handlers import handle_rpc_exceptions | ||
from mathesar.rpc.utils import connect | ||
|
||
|
@@ -67,6 +70,41 @@ def get(*, table_oid: int, database_id: int, **kwargs) -> TableInfo: | |
return TableInfo(raw_table_info) | ||
|
||
|
||
@rpc_method(name="tables.add") | ||
@http_basic_auth_login_required | ||
@handle_rpc_exceptions | ||
def add( | ||
*, | ||
table_name: str, | ||
schema_oid: int, | ||
database_id: int, | ||
column_data_list: list[CreateableColumnInfo] = [], | ||
constraint_data_list: list[CreateableConstraintInfo] = [], | ||
comment: str = None, | ||
**kwargs | ||
) -> int: | ||
""" | ||
Add a table with a default id column. | ||
|
||
Args: | ||
table_name: Name of the table to be created. | ||
schema_oid: Identity of the schema in the user's database. | ||
database_id: The Django id of the database containing the table. | ||
column_data_list: A list describing columns to be created for the new table, in order. | ||
constraint_data_list: A list describing constraints to be created for the new table. | ||
comment: The comment for the new table. | ||
|
||
Returns: | ||
The `oid` of the created table. | ||
""" | ||
user = kwargs.get(REQUEST_KEY).user | ||
with connect(database_id, user) as conn: | ||
created_table_oid = create_table_on_database( | ||
table_name, schema_oid, conn, column_data_list, constraint_data_list, comment | ||
) | ||
return created_table_oid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may need to enhance this return value. The current endpoint returns a blob describing the created table whenever one is created. OTOH, the only info in the blob we have set up for Let's merge as-is, and keep a mental note to watch for feature requests from the front end on this. |
||
|
||
|
||
@rpc_method(name="tables.delete") | ||
@http_basic_auth_login_required | ||
@handle_rpc_exceptions | ||
|
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.
At some point, we need to figure out a way to use inheritance here in a way that preserves the documentary value of these classes.