From b50a6a02f9b42e2c993f556204347a5a682b13bd Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Wed, 1 Dec 2021 16:47:54 +0000 Subject: [PATCH] add Char column type --- piccolo/apps/schema/commands/generate.py | 3 +++ piccolo/columns/column_types.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/piccolo/apps/schema/commands/generate.py b/piccolo/apps/schema/commands/generate.py index 035a95e61..39e0b694d 100644 --- a/piccolo/apps/schema/commands/generate.py +++ b/piccolo/apps/schema/commands/generate.py @@ -21,6 +21,7 @@ BigInt, Boolean, Bytea, + Char, Date, DoublePrecision, ForeignKey, @@ -268,6 +269,7 @@ def __add__(self, value: OutputSchema) -> OutputSchema: "bigint": BigInt, "boolean": Boolean, "bytea": Bytea, + "char": Char, "character varying": Varchar, "date": Date, "integer": Integer, @@ -289,6 +291,7 @@ def __add__(self, value: OutputSchema) -> OutputSchema: Boolean: re.compile(r"^(?Ptrue|false)$"), Bytea: re.compile(r"'(?P.*)'::bytea$"), DoublePrecision: re.compile(r"(?P[+-]?(?:[0-9]*[.])?[0-9]+)"), + Char: re.compile(r"^'(?P.*)'::bpchar$"), Varchar: re.compile(r"^'(?P.*)'::character varying$"), Date: re.compile(r"^(?P(?:\d{4}-\d{2}-\d{2})|CURRENT_DATE)$"), Integer: re.compile(r"^(?P-?\d+)$"), diff --git a/piccolo/columns/column_types.py b/piccolo/columns/column_types.py index edaeccb26..70ce860cc 100644 --- a/piccolo/columns/column_types.py +++ b/piccolo/columns/column_types.py @@ -199,6 +199,15 @@ def __radd__(self, value: t.Union[str, Varchar, Text]) -> QueryString: ) +class Char(Varchar): + """ + This is the same as ``Varchar`` in SQLite. + + In Postgres it is 'blank padded'. For example, if the length is 5, and you + store `'foo'`, then you will get ``'foo '`` back from the database. + """ + + class Secret(Varchar): """ This is just an alias to ``Varchar(secret=True)``. It's here for backwards