Documentation for creating custom column types

32 views
Skip to first unread message

xcdc dxcx

unread,
Aug 16, 2019, 9:53:46 PM8/16/19
to Rose::DB::Object
Hello.

Is there documentation about creating custom column types for use within RDBO?

From searching, I was able to understand that my custom column type needs to be registered with the metadata using:

__PACKAGE__->meta->column_type_class('new_type_name', 'My::Column::Implementation::Class')

but I still have no idea how to actually go about implementing the My::Column::Implementation::Class.

I have read the '[RDBO] Custom SQL for columns' topic on the old mailing list ( https://www.mail-archive.com/rose-db...@lists.sourceforge.net/msg00710.html ) but it does not tell the full story.
I have read the ::Metadata::Column documentation ( https://metacpan.org/pod/Rose::DB::Object::Metadata::Column ) but that did not answer any of my questions.
I have tried looking at existing (default) column types, but I was not able to gain understanding of it, because even the simplest of the types (for example https://metacpan.org/release/Rose-DB-Object/source/lib/Rose/DB/Object/Metadata/Column/Scalar.pm ) seem to be magic on top of magic.

A tutorial of how to go about this from the ground up would be much welcome.

Peter Karman

unread,
Aug 20, 2019, 5:53:49 AM8/20/19
to rose-db...@googlegroups.com
xcdc dxcx wrote on 8/16/19 8:53 PM:
You probably have found
https://metacpan.org/pod/Rose::DB::Object::Metadata::Column by now.

Then take a look at
https://metacpan.org/pod/Rose::DB::Object::Metadata::Column::Datetime for
example of how a column type is implemented.

HTH,
pek


--
Peter Karman . he/him/his . 785.337.0405 . https://karpet.github.io/

Peter Karman

unread,
Aug 20, 2019, 6:02:24 AM8/20/19
to rose-db...@googlegroups.com
Well my previous answer obviously didn't help. If I had read more carefully I'd have noticed you've already looked at those docs.

Based on my reading of those same docs, I would try something like (UNTESTED):

package MyColumn;
use base qw( Rose::DB::Object::Metadata::Column );

Rose::Object::MakeMethods::Generic->make_methods
(
  { preserve_existing => 1 },
  scalar => [ __PACKAGE__->common_method_maker_argument_names ]
);
 
foreach my $type (__PACKAGE__->available_method_types)
{
  __PACKAGE__->method_maker_type($type => 'my_type');
}
 
sub type { 'my_type' }

sub parse_value
{
  my($self, $db, $column_value) = (shift, shift, shift);
 
  $self->parse_error(undef);

  # do something with $column_value read from db

  return $column_value
}

sub format_value {
  my ($self, $input_value) = @_;

  # do something with $input_value will be written to db

  return $input_value;
}

1;


That help?

pek

--
Source: https://github.com/siracusa/rose
CPAN: http://search.cpan.org/dist/Rose-DB-Object
---
You received this message because you are subscribed to the Google Groups "Rose::DB::Object" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rose-db-objec...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rose-db-object/ebc02e95-0ca4-4588-ab46-9afb7aa5c419%40googlegroups.com.


--
Peter Karman  .  he/him/his  .  https://karpet.github.io/

xcdc dxcx

unread,
Aug 22, 2019, 9:41:05 AM8/22/19
to Rose::DB::Object
Hello Peter.

This is a useful example, however I am looking for documentation that will explain the following:
1) list of methods the new column type is expected to provide and may optionally provide (in other words, the interface that wil be called by RDBO class that will use it)
2) API reference of methods/functions available to a column class. For example, in https://metacpan.org/release/Rose-DB-Object/source/lib/Rose/DB/Object/Metadata/Column/Datetime.pm I see the usage of __PACKAGE__->add_common_method_maker_argument_names, __PACKAGE__->common_method_maker_argument_names and $self->parse_error, and in https://metacpan.org/release/Rose-DB-Object/source/lib/Rose/DB/Object/Metadata/Column/Scalar.pm I see things like init_with_dbi_column_info and default_overflow, and none of this seems to be documented anywhere
3) documentation for types taken returned by the above methods, especially for those that operate on strings. It is not clear if the API works with encoded strings (bytes/octets) or decoded (characters/codepoints).

I have read the '[RDBO] Custom SQL for columns' topic on the old mailing list ( https://www.mail-archive.com/rose-db-object@lists.sourceforge.net/msg00710.html ) but it does not tell the full story.
I have read the ::Metadata::Column documentation ( https://metacpan.org/pod/Rose::DB::Object::Metadata::Column ) but that did not answer any of my questions.
I have tried looking at existing (default) column types, but I was not able to gain understanding of it, because even the simplest of the types (for example https://metacpan.org/release/Rose-DB-Object/source/lib/Rose/DB/Object/Metadata/Column/Scalar.pm ) seem to be magic on top of magic.

A tutorial of how to go about this from the ground up would be much welcome.

--
Source: https://github.com/siracusa/rose
CPAN: http://search.cpan.org/dist/Rose-DB-Object
---
You received this message because you are subscribed to the Google Groups "Rose::DB::Object" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rose-db...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages