-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
Custom python class to represent "char"
DB type
#1214
Comments
@mathemancer I would like to work upon this issue. |
Go ahead @Cronus1007 |
@Cronus1007 Please don't hesitate to ask if you have questions. Please get one type done (rather than both) and submit a PR, or at least a draft, so we can see how it's going. |
@mathemancer Sure. Thanks 👍 |
Hey @Cronus1007, this has become a dependency for a refactor I'm working on. I'd like to collaborate. Can we discuss this on matrix? My handle is |
@dmos62 Sure 👍
@mathemancer Can you please elaborate this statement? |
If you create an SQLAlchemy |
@mathemancer Any specific file where this code should be placed or shall I create a new file? |
You'll need to create two new files in the |
@Cronus1007 as I mentioned in Matrix, this isn't a dependency of mine anymore, but here's something I came up with while I thought that it was. I didn't test this. You should be able to use the same setup for from sqlalchemy.dialects.postgresql import VARCHAR as SA_VARCHAR
from sqlalchemy.types import TypeDecorator
from sqlalchemy.ext.compiler import compiles
from db.types.base import PostgresType
class CHARACTER_VARYING(TypeDecorator):
impl = SA_VARCHAR
cache_ok = True
@classmethod
def __str__(cls):
return cls.__name__
@compiles(CHARACTER_VARYING, 'postgresql')
def _compile_character_varying(element, compiler, **kw):
unchanged_compiled_string = compiler.visit_VARCHAR(element, **kw)
unchanged_id = "VARCHAR"
changed_id = PostgresType.CHARACTER_VARYING.value.upper()
changed_compiled_string = unchanged_compiled_string.replace(unchanged_id, changed_id)
return changed_compiled_string |
@dmos62 @mathemancer
@mathemancer @dmos62 Any suggestions about this approach? |
A few things:
Edit: If you have more specific questions about the trouble you're having with compilation, I might be able to provide better help. |
No I was just focusing more upon the UserDefinedType as the ticket mentioned.
Sure I would go ahead In this way.
No since I am very new to the codebase and sqlachemy so I don't have much specific questions related to the compilation but if I would have any specific error while resolving the issue then would definitely refer you. @mathemancer Can you plzz share your matrix handle for discussions? I would be raising a draft pr by eod. |
@brent:matrix.mathesar.org |
@mathemancer @dmos62 Is there any way I would be able to test that whether the changes I have done are working correctly? |
@Cronus1007 I'll answer on the PR, since that will be easier to track. |
@mathemancer @dmos62 I have completed work of '"char"' from my side in the PR linked. Once the PR gets merged I would love to start the work for name key as well. |
Fixes #1214: Intital setup of class to represent CHAR db
@mathemancer The PR#1260 doesn't close this issue. I need to build the python class for name as well so can you please reopen this issue so that I will be able to complete that as well. |
Ah, that's correct. |
@Cronus1007 are you still working on this? |
Doesn't seem interesting anymore now that we're removing SQLAlchemy. Might be different if this didn't require a fair bit of input from core team. |
Problem
Currently, a columns of types
NAME
or"char"
in the database show up as typeVARCHAR
in the API. This is because SQLAlchemy reflects these types as theString
python class, which compiles toVARCHAR
in thepostgres
dialect.Proposed solution
We should:
UserDefinedType
representing"char"
, and another representingNAME
.engine.dialect.ischema_names
dictionary under the'"char"'
and'name'
keys, respectively. (note that the string contains double-quotes)Additional context
Based on a discussion: #1184
The text was updated successfully, but these errors were encountered: