Skip to content

ColumnSerializable implementation is incomplete #1591

Open
0 of 1 issue completed
Open

Description

@lukehutch

Describe the bug

In columns.dart:

/// A [Column] holding an [SerializableEntity]. The entity will be stored in the
/// database as a json column.
class ColumnSerializable extends Column<String> {
  /// Creates a new [Column], this is typically done in generated code only.
  ColumnSerializable(super.columnName, super.table);

// TODO: Add comparisons and possibly other operations
}

At a minimum, this needs to support isNotNull() or similar, so that List<T>? types can be checked for nullness.

Sub-issues

Sub-issues

0 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    enhancement
    on Nov 22, 2023
  2. SandPod commented on Nov 22, 2023

    @SandPod
    Contributor

    You are correct, the implementation for ColumnSerializable does not yet support any column operations.
    This needs to be implemented 👍

  3. lukehutch commented on Feb 4, 2024

    @lukehutch
    ContributorAuthor

    Yes, nothing has changed

  4. SandPod commented on Feb 12, 2024

    @SandPod
    Contributor

    @al-ik Yes, this is still free and open for taking.

  5. xyzbilal commented on Aug 17, 2024

    @xyzbilal

    is there any work for it?
    I have a table that defines vouchers for users and I want to create report that how many vouchers a user used. if a user use voucher code I just want to add users id to usersIdsAlreadyUsed column. then when I want to see statics for the user I want to list vouchers used by user by checking usersIdsAlreadyUsed column.

    class: Voucher
    table: vouchers
    fields:
      creatorUserId: int,
      code: String,
      price: double?,
      discount: double?,
      description: String?,
      type: VoucherType,
      books: List<Book>?
      subscriptions: List<Subscription>?
      total: int
      used: int
      usersIdsAlreadyUsed: List<int>?
      startDate: DateTime
      endDate: DateTime
    
    indexes:
      vouchers_title_unique_idx:
        fields: code
        unique: true
    

    I now try to use this function for this purpose but Im not sure if its safe and good practice to use

     Future<List<Voucher>> getVouchersByUser(Session session,int userId) async {
    
        // ? Eğer kullanıcı bunu bir sefer kullandıysa tekrar kullanamaz.
    
      DatabaseResult result = await session.db.unsafeQuery(
      r'SELECT * FROM vouchers WHERE  usersIdsAlreadyUsed @> $1::int[]',
      parameters: QueryParameters.positional([
        [userId],  
      ]),
    );
    
        return result.toList().map((e) => Voucher.fromJson(e.toColumnMap())).toList();
      }
    

    If you give me a reference link I believe I also can add some features for ColumnSerializable class.

    Thanks.

  6. binemmanuel commented on Oct 25, 2024

    @binemmanuel

    I despise the fact that I have to write an SQL query for this and serialise the data myself, resulting in this much latency 🤦🏾‍♂️🤦🏾‍♂️

    METHOD CALL: errand.getAll duration: 116ms numQueries: 0 authenticatedUser: 21

    Thanks to caching, I'm able to reduce latency

    METHOD CALL: errand.getAll duration: 7ms numQueries: 0 authenticatedUser: 21

    unsafe

  7. added
    area: database
    and removed
    enhancement
    on Dec 18, 2024
  8. iampopal commented on Jul 14, 2025

    @iampopal

    I need this too. looking for it.

  9. iampopal commented on Aug 5, 2025

    @iampopal

    Looking for a solution for this...

  10. iampopal commented on Apr 15, 2026

    @iampopal

    How's progress of this going, when can we get this?

  11. marcelomendoncasoares commented on Apr 15, 2026

    @marcelomendoncasoares
    Collaborator

    How's progress of this going, when can we get this?

    @iampopal There is no current work being done on this. We are restoring the work on JSONB support, which will be important for column operations on stored objects. Once JSONB is in, we're open to receive contributions for this feature.

  12. enesbugrahankilic commented on Aug 31, 2026

    @enesbugrahankilic

    Opening a PR to add null-comparison operations to ColumnSerializable.

  13. added 2 commits that reference this issue on Aug 31, 2026
    f10084d
    50b1377
  14. rajput-abdullah commented on Sep 1, 2026

    @rajput-abdullah

    So the issue is that ColumnSerializable in columns.dart still has that TODO the maintainers left about comparisons not being finished, and lukehutch called out the actual gap you can't check nullness on a nullable list column like List?. Basically I can't write a query that says "give me rows where this list column isn't null."

    My plan: go find wherever the existing comparison operators live on that class Serverpod's query columns pretty much mirror SQL operators (equals, notEquals, etc.), each one building an Expression under the hood and add an isNotNull() that follows the same pattern, just emitting IS NOT NULL. Rough shape of what it'd probably look like:

    dart
    Expression isNotNull() {
    return Expression('$queryAlias.$columnName IS NOT NULL');
    }

    Before I actually touch anything I'm going to pull the repo, open columns.dart, and see how isNull() or any other comparator is written, then copy that structure exactly so it doesn't look bolted on. I'll add a test next to the existing column tests too. There are already two PRs linked on the issue (#5656, #5354) — gonna check those first so I'm not duplicating someone else's work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: databasegood first issue

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions