Λογότυπο Hor Sequelize Subquery

Hor Sequelize Subquery

Οργανισμός
openreachtech
hor-sequelize-subquery

Define and consume named Sequelize subqueries on renchan models (this.addSubquery inside defineSubqueries in sequelize/models/*.js, consumed via Model.subquery(name, params) under Op.in in a where clause). Use this skill whenever a query must filter rows by a condition on a related / associated table — in this convention that is a subquery, not a JOIN — or whenever the user asks to define, name, or test a subquery.

Επισκόπηση

Εκδότηςopenreachtech
Αποθετήριοhora-skills-ort-renchan
Όνομα δεξιότηταςhor-sequelize-subquery
Αστέρια
32
Forks
0
Συνοδευτικά αρχεία
Μόνο οδηγίες
Άδεια χρήσηςApache-2.0
Σύνδεσμοι
  • Οδηγίες σε Markdown

    Ένα αρχείο SKILL.md που το μοντέλο φορτώνει όταν χρειάζεται, ώστε να καταναλώνει token μόνο όταν ένα αίτημα είναι πράγματι σχετικό.

  • Λειτουργεί με οποιοδήποτε LLM

    Οι δεξιότητες AI είναι απλό Markdown, όχι κώδικας για συγκεκριμένο πάροχο, επομένως αυτή η δεξιότητα λειτουργεί με GPT, Claude, Gemini, Grok ή ένα τοπικό μοντέλο.

  • Αυτοτελής

    Όλα όσα χρειάζεται το μοντέλο περιλαμβάνονται στις οδηγίες — χωρίς επιπλέον αρχεία για συγχρονισμό.

  • Ανοιχτού κώδικα

    Δημοσιεύτηκε από openreachtech στο GitHub. Διαβάστε το πηγαίο περιεχόμενο πριν εγκαταστήσετε τη δεξιότητα.

Εγκατάσταση

Εγκαταστήστε τη δεξιότητα AI Hor Sequelize Subquery στο TypingMind για να τη χρησιμοποιείτε με οποιοδήποτε LLM ή προσθέστε τη σε άλλον πράκτορα AI που διαβάζει αρχεία SKILL.md.

1

Εγκατάσταση στο TypingMind

Το TypingMind εγκαθιστά μια δεξιότητα απευθείας από τον φάκελό της στο GitHub — διαβάζει το SKILL.md, συγκεντρώνει τα συνοδευτικά αρχεία σε πακέτο και αποθηκεύει το αποτέλεσμα τοπικά.

  1. Ανοίξτε την εφαρμογή και μεταβείτε στα Πρόσθετα → Δεξιότητες.
  2. Επιλέξτε «Εγκατάσταση από GitHub».
  3. Επικολλήστε το παρακάτω URL του φακέλου της δεξιότητας και επιβεβαιώστε.
    https://github.com/openreachtech/hora-skills-ort-renchan/tree/main/kit/skills/hor-sequelize-subquery
  4. Ενεργοποιήστε τη δεξιότητα σε κάθε συνομιλία όπου θέλετε να είναι διαθέσιμη.
Πρόσθετα → Δεξιότητες → Νέα δεξιότητα → Από URL του GitHub, έπειτα επικολλήστε το URL του φακέλου και πατήστε «Συνέχεια».
2

Εγκατάσταση σε άλλον πράκτορα AI

Κάθε πράκτορας AI που διαβάζει τη μορφή Agent Skills μπορεί να χρησιμοποιήσει αυτή τη δεξιότητα — αντιγράψτε τον φάκελο στον κατάλογο δεξιοτήτων του.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/openreachtech/hora-skills-ort-renchan.git /tmp/hora-skills-ort-renchan
mkdir -p .claude/skills
cp -r /tmp/hora-skills-ort-renchan/kit/skills/hor-sequelize-subquery .claude/skills/hor-sequelize-subquery
Επανεκκινήστε το Claude Code μετά την αντιγραφή, ώστε να εντοπίσει τη νέα δεξιότητα.

Χρησιμοποιήστε τη στο TypingMind

Ενεργοποιήστε τη δεξιότητα Hor Sequelize Subquery σε οποιαδήποτε συνομιλία στο TypingMind και το μοντέλο αναλαμβάνει τα υπόλοιπα. Το όνομα και η περιγραφή της περιλαμβάνονται στην προτροπή συστήματος και, μόλις προκύψει ένα σχετικό αίτημα, το μοντέλο φορτώνει μόνο του τις πλήρεις οδηγίες — δεν χρειάζεται ποτέ να την καλείτε χειροκίνητα και δεν καταναλώνει token μέχρι να χρησιμοποιηθεί πραγματικά.

Το μοντέλο φορτώνει αυτόματα τη δεξιότητα Hor Sequelize Subquery μόλις λάβει ένα σχετικό αίτημα.

Λειτουργεί με οποιοδήποτε μοντέλο AI

Οι δεξιότητες AI είναι απλές οδηγίες Markdown και όχι κώδικας για συγκεκριμένο πάροχο, οπότε η δεξιότητα Hor Sequelize Subquery δεν περιορίζεται στο μοντέλο για το οποίο γράφτηκε. Εγκαταστήστε τη μία φορά στο TypingMind και χρησιμοποιήστε τη με GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama ή ένα τοπικό μοντέλο που εκτελείτε εσείς — πάντα με τα δικά σας κλειδιά API.

  • Φόρτωση μόνο όταν χρειάζεται

    Η προτροπή συστήματος περιλαμβάνει μόνο το όνομα και την περιγραφή. Οι οδηγίες ανακτώνται με το πρώτο σχετικό αίτημα, οπότε μια δεξιότητα που δεν χρησιμοποιείται δεν έχει κόστος.

  • Αλλάξτε μοντέλα κατά τη συνομιλία

    Επειδή η δεξιότητα αποτελείται από οδηγίες και όχι από κώδικα, η αλλαγή μοντέλου δεν επηρεάζει τη λειτουργία της — το επόμενο μοντέλο διαβάζει το ίδιο αρχείο SKILL.md.

Οδηγίες δεξιότητας

Αυτό είναι το περιεχόμενο του αρχείου SKILL.md που φορτώνει το μοντέλο. Διαβάστε το πριν από την εγκατάσταση — μια δεξιότητα αποτελείται από οδηγίες που θα ακολουθήσει το μοντέλο σας.

Sequelize Subquery

A skill for defining named, reusable SELECTs attached to a Sequelize model, and consuming them from a resolver's where clause. A subquery is registered once on the model with this.addSubquery({ name, generator }) and consumed with Model.subquery(name, params), which returns a Sequelize.Literal (a real SQL subquery) — so you filter one model by the result of a SELECT against another without writing a join or a raw SQL string at the call site.

Registration lives in static defineSubqueries(), one of the six extension points of the model skeleton defined in hor-sequelize-model (an unused defineSubqueries stays as a noop there; this skill covers what to write when it is used). The consuming side (building a resolver's where clause) belongs to hor-query-resolver / hor-mutation-resolver; testing follows hoc-jest.

Grand principle: the name is the query — a self-describing string registered on the model

The subquery API comes from RenchanModel in @openreachtech/renchan-sequelize — never roll your own (no raw Sequelize.literal('SELECT ...') at a call site, no ad-hoc join to express a cross-table filter). Register the SELECT on the model that owns it, and give it a name that encodes exactly its where conditions and its select columns:

?<cond1>[<op1>]?<cond2>[<op2>].<result1>.<result2>
  • Condition columns (the where) each start with ?. The operator goes in square brackets [...] immediately after the column name; a plain equality has no brackets.
  • Result columns (the select) each start with ..
  • The table name never appears in the name. The subquery is added to a target model, so the table is self-evident from the model — the name encodes only conditions and results.
  • Why a self-describing name: the consumer reads '?CustomerId.id' and knows, without opening the model, that it means "WHERE customer_id = ?, SELECT id". A free-form name ('ordersOfCustomer') forces every reader back to the definition, and drifts silently when the definition changes.
  • Why registered on the model, not inlined at the call site: the same cross-table filter is typically needed by several resolvers. A raw literal written inline duplicates SQL strings, escapes nothing into the model layer, and cannot be unit-tested as a pure generator.
js
// Good: consume a named subquery registered on the model
const customerOrderSubquery = CustomerOrder.subquery('?CustomerId.id', {
  customerId,
})

const whereClause = {
  CustomerOrderId: {
    [Op.in]: customerOrderSubquery,
  },
}
js
// Avoid: raw SQL literal at the call site
//   → duplicates the SELECT wherever it is needed, leaks physical column names
//     into the resolver, and cannot be tested as a pure generator.
const whereClause = {
  CustomerOrderId: {
    [Op.in]: Sequelize.literal(
      `(SELECT id FROM customer_orders WHERE customer_id = ${customerId})`
    ),
  },
}

Comment language in the sample code

Comments in the js examples in this SKILL.md follow the prose language (here, English), because the examples are explanation of the skill. Comments inside the artifact this skill produces (the real model / resolver code) follow the codebase language — English — to match the surrounding source.

1. When to reach for a subquery

Reach for a subquery when a resolver needs to constrain rows of model A by a condition that lives on model B. Typical cases:

RequirementShape
"Payments of the orders that belong to this customer"Filter OrderPayment by CustomerOrderId IN (SELECT id FROM customer_orders WHERE customer_id = ?)
"Shipments whose latest status is in a given set"Filter Shipment by id IN (SELECT shipment_id FROM shipment_latest_statuses WHERE shipment_status_id IN (...))
"Coupons valid at a point in time"Filter by id IN (SELECT coupon_id FROM coupon_settings WHERE valid_from <= ? AND valid_until >= ?)
  • The subquery is defined on the model that owns the condition columns (the model whose table the inner SELECT reads), and its result columns are what the outer where matches against (usually an id / FK column).
  • If the requirement is "load B together with A for output", that is an include association (hor-sequelize-model → associations), not a subquery. A subquery is for filtering, not eager-loading.

2. Naming convention and operator table

The operator inside [...] maps to a Sequelize Op symbol in the generator's where:

formatmeaning
(none)set as value directly (plain equality)
[=]Op.eq
[>]Op.gt
[>=]Op.gte
[<]Op.lt
[<=]Op.lte
[in]Op.in
[between]Op.between
[like]Op.like
  • "Set as value directly": when a condition is a plain equality, omit the brackets and assign the value straight onto the field — ?CustomerId.id with a where of { [CustomerIdField]: customerId }.
  • Reading examples:
    • ?CustomerId.id — "WHERE CustomerId = ?, SELECT id"
    • ?ShipmentStatusId[in].ShipmentId — "WHERE ShipmentStatusId IN (...), SELECT ShipmentId"
    • ?validFrom[<=].validUntil[>=].CouponId — two conditions, each with its own operator
    • ?OriginObjectCategoryId?jobDivisionNumber.id — two equality conditions (no brackets), one result

3. Register the subquery in defineSubqueries()

Register inside static defineSubqueries(). Call super.defineSubqueries?.() first (as with every extension point in hor-sequelize-model — otherwise a Mixin's base behavior is lost), read the physical field names off this.getAttributes(), then add each subquery with this.addSubquery({ name, generator }).

The generator receives a params object and returns { attributes, where }:

  • attributes — the SELECT column list, as DB field names (take them from this.getAttributes().<key>.field, never hard-code snake_case strings).
  • where — a Sequelize where clause, keyed by DB field names, using the Op symbols that the subquery name declares.

Basic example (single equality condition, single result):

js
/**
 * Define model subqueries
 *
 * @override
 */
static defineSubqueries () {
  super.defineSubqueries?.()

  const allAttributes = this.getAttributes()
  const idField = allAttributes.id.field
  const CustomerIdField = allAttributes.CustomerId.field

  this.addSubquery({
    name: '?CustomerId.id',
    generator: ({
      customerId,
    }) => {
      const attributes = [
        idField,
      ]

      const whereClause = {
        [CustomerIdField]: customerId,
      }

      return {
        attributes,
        where: whereClause,
      }
    },
  })
}

Advanced example (two conditions, each with its own operator, single result):

js
this.addSubquery({
  name: '?validFrom[<=].validUntil[>=].CouponId',
  generator: ({
    now,
  }) => {
    const attributes = [
      CouponIdField,
    ]

    const whereClause = {
      [validFromField]: {
        [SequelizeOp.lte]: now,
      },
      [validUntilField]: {
        [SequelizeOp.gte]: now,
      },
    }

    return {
      attributes,
      where: whereClause,
    }
  },
})
  • The Op symbols come from the top of the model file:
js
import {
  Op as SequelizeOp,
} from 'sequelize'
  • The name and the generator must agree. Every ? column in the name appears in where with exactly the operator its brackets declare; every . column appears in attributes. A name that says [in] while the generator assigns a direct value is a bug — the name is the contract.

4. Consume via Model.subquery(name, params) under Op.in

Call Model.subquery(name, params) — it returns a Sequelize.Literal — and drop it into a where clause, almost always as the right-hand side of an Op.in. Typical resolver usage (inside a buildXxxWhereClause() method, per hor-query-resolver):

js
import {
  Op,
} from 'sequelize'

// ...

/**
 * Build where clause for shipments.
 *
 * @param {{
 *   tenantBrandId: number
 * }} params - Parameters.
 * @returns {object} Where clause.
 */
buildShipmentWhereClause ({
  tenantBrandId,
}) {
  const shipmentLatestStatusSubquery = ShipmentLatestStatus.subquery(
    '?ShipmentStatusId[in].ShipmentId',
    {
      shipmentStatusIds: [SHIPMENT_STATUS.READY_TO_SHIP.ID],
    }
  )

  const whereClause = {
    TenantBrandId: tenantBrandId,
    id: {
      [Op.in]: shipmentLatestStatusSubquery,
    },
  }

  return whereClause
}

Combining two subqueries on the same column uses Op.and:

js
return {
  ...whereClause,
  id: {
    [Op.and]: [
      {
        [Op.in]: shipmentLatestStatusSubquery,
      },
      {
        [Op.in]: desiredDeliveryDateSubquery,
      },
    ],
  },
}
  • Calling Model.subquery(name, ...) with a name that was never registered throws invalid subquery ${name} called. — the name string at the call site must match the registered name character for character.

5. Testing

Test the generator, not the SQL string. Pull it with Model.getSubqueryOptionsGenerator(name), invoke it with params, and assert the returned { attributes, where } with a single toEqual. The generator is pure (no DB access), so the test needs no seeder and lives under tests/__tests__/sequelize/models/ (per hoc-jest — DB-writing tests are the ones that go elsewhere).

Structure: describe('<Model>') → describe('.subquery') → describe('<subquery name>') → test.each. Import Op from sequelize so the expected where carries the real operator symbols.

js
import {
  Op,
} from 'sequelize'

import ShipmentLatestStatus from '../../../../sequelize/models/ShipmentLatestStatus.js'

describe('ShipmentLatestStatus', () => {
  describe('.subquery', () => {
    describe('?ShipmentStatusId[in].ShipmentId', () => {
      const cases = [
        {
          params: {
            shipmentStatusIds: [10001, 10002],
          },
          expected: {
            attributes: ['shipment_id'],
            where: {
              shipment_status_id: {
                [Op.in]: [10001, 10002],
              },
            },
          },
        },
        {
          params: {
            shipmentStatusIds: [10003],
          },
          expected: {
            attributes: ['shipment_id'],
            where: {
              shipment_status_id: {
                [Op.in]: [10003],
              },
            },
          },
        },
      ]

      test.each(cases)('shipmentStatusIds[0]: $params.shipmentStatusIds.0', ({
        params,
        expected,
      }) => {
        const generator = ShipmentLatestStatus.getSubqueryOptionsGenerator('?ShipmentStatusId[in].ShipmentId')

        const actual = generator(params)

        expect(actual)
          .toEqual(expected)
      })
    })
  })
})

Conventions to keep (details in hoc-jest):

  • test.each, prefer ≥ 2 cases (vary the params); a trivial single-condition subquery may use one case. Vary exactly one params field in the title and keep it unique per case — dot into an array element as needed ($params.shipmentStatusIds.0).
  • Cases are { params, expected } — no other keys unless justified.
  • One toEqual for the whole returned object; build the full expected (including Op symbols) and compare once.
  • AAA, no logic in the body — arrange the generator, act by calling it, assert.
  • The expected attributes / where keys are the DB field names (snake_case) — that is what the generator returns, and it verifies the attribute-to-field mapping too.
  • Test a subquery against real seeded data only when exercising it end-to-end through a resolver that reads the DB — that is a resolver test, placed per hoc-jest's directory rules.

Finishing checklist

  • Does the subquery live in static defineSubqueries() on the model that owns the condition columns, added via this.addSubquery({ name, generator }) (no raw Sequelize.literal at call sites)?
  • Does defineSubqueries() call super.defineSubqueries?.() first, and take field names from this.getAttributes() (no hard-coded snake_case strings)?
  • Does the name follow ?<condition>[<operator>].<result> — every ? column in where with exactly the declared operator, every . column in attributes, no brackets for plain equality, and no table name?
  • Does the generator return { attributes, where } keyed by DB field names?
  • Does the consumer call Model.subquery(name, params) under Op.in (with Op.and when combining two subqueries on the same column), with the name matching the registration exactly?
  • Is the generator tested via Model.getSubqueryOptionsGenerator(name) with test.each { params, expected } cases and a single toEqual (including the real Op symbols), placed under tests/__tests__/sequelize/models/?

Συχνές ερωτήσεις

Τι κάνει η δεξιότητα AI Hor Sequelize Subquery;

Define and consume named Sequelize subqueries on renchan models (this.addSubquery inside defineSubqueries in sequelize/models/*.js, consumed via Model.subquery(name, params) under Op.in in a where clause). Use this skill whenever a query must filter rows by a condition on a related / associated table — in this convention that is a subquery, not a JOIN — or whenever the user asks to define, name, or test a subquery.

Γιατί να χρησιμοποιήσετε τη δεξιότητα Hor Sequelize Subquery στο TypingMind;

Επειδή την εγκαθιστάτε μία φορά και τη χρησιμοποιείτε με οποιοδήποτε μοντέλο. Η Hor Sequelize Subquery είναι απλό Markdown και όχι κώδικας ειδικά για κάποιον πάροχο, επομένως η ίδια δεξιότητα λειτουργεί με GPT-5, Claude, Gemini, Grok ή ένα τοπικό μοντέλο — και μπορείτε να αλλάξετε μοντέλο κατά τη διάρκεια της συνομιλίας χωρίς να διακοπεί η λειτουργία της. Το TypingMind λειτουργεί με τα δικά σας κλειδιά API, οπότε πληρώνετε απευθείας τους παρόχους αντί για συνδρομή ανά θέση χρήστη, ενώ οι δεξιότητες και οι συνομιλίες σας παραμένουν στον δικό σας χώρο αποθήκευσης.

Πώς εγκαθιστώ τη Hor Sequelize Subquery στο TypingMind;

Στο TypingMind, ανοίξτε Πρόσθετα → Δεξιότητες → Εγκατάσταση από το GitHub και επικολλήστε το https://github.com/openreachtech/hora-skills-ort-renchan/tree/main/kit/skills/hor-sequelize-subquery. Το TypingMind διαβάζει το αρχείο SKILL.md και εγκαθιστά τη δεξιότητα, την οποία μπορείτε να ενεργοποιείτε ανά συνομιλία.

Ποια μοντέλα AI μπορούν να χρησιμοποιήσουν τη δεξιότητα Hor Sequelize Subquery;

Οποιοδήποτε μοντέλο συνδέετε στο TypingMind. Οι δεξιότητες AI είναι απλές οδηγίες Markdown και όχι κώδικας ειδικά για κάποιον πάροχο, επομένως τα GPT, Claude, Gemini, Grok και τα τοπικά μοντέλα μπορούν όλα να φορτώσουν αυτή τη δεξιότητα όταν ένα αίτημα αντιστοιχεί σε αυτή.

Με πόσα μοντέλα AI μπορώ να χρησιμοποιήσω τη Hor Sequelize Subquery;

Με όσα θέλετε. Εφόσον ένα μοντέλο υποστηρίζει δεξιότητες, μπορείτε να χρησιμοποιήσετε τη Hor Sequelize Subquery με αυτό — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama και άλλα — όλα στο TypingMind με τα δικά σας κλειδιά API.

Είναι δωρεάν η δεξιότητα AI Hor Sequelize Subquery;

Ναι. Δημοσιεύεται στο GitHub από τον χρήστη openreachtech με την άδεια χρήσης Apache-2.0. Πληρώνετε μόνο τον δικό σας πάροχο AI για τα token που χρησιμοποιείτε.

Τι είναι οι δεξιότητες AI;

Μια δεξιότητα AI είναι ένα επαναχρησιμοποιήσιμο πακέτο οδηγιών που διδάσκει σε ένα μοντέλο AI πώς να εκτελεί μια συγκεκριμένη εργασία. Ακολουθεί την ανοιχτή μορφή Agent Skills: ένα αρχείο SKILL.md με όνομα και περιγραφή, μαζί με τυχόν σενάρια κώδικα, πρότυπα ή αρχεία αναφοράς που μπορεί να χρειαστεί το μοντέλο. Το μοντέλο διαβάζει τις οδηγίες μόνο όταν το αίτημά σας αντιστοιχεί στη δεξιότητα, οπότε μια εγκατεστημένη δεξιότητα δεν κοστίζει τίποτα μέχρι να χρησιμοποιηθεί.

Σε τι διαφέρουν οι δεξιότητες AI από τα πρόσθετα ή τους συνδέσμους MCP;

Ένα πρόσθετο ή ένας σύνδεσμος MCP παρέχει στο μοντέλο νέα εργαλεία που μπορεί να καλέσει — κώδικα που εκτελείται κάπου και επιστρέφει ένα αποτέλεσμα. Μια δεξιότητα AI παρέχει αντί γι’ αυτό γνώσεις και διαδικασίες στο μοντέλο: πώς να προσεγγίσει μια εργασία, ποια βήματα να ακολουθήσει και ποια χαρακτηριστικά έχει ένα καλό αποτέλεσμα. Οι δεξιότητες είναι απλό Markdown, επομένως δεν χρειάζονται διακομιστή, κλειδί API ή περιβάλλον εκτέλεσης και λειτουργούν με οποιοδήποτε μοντέλο.

Προβολή όλων

Στήστε δικό σας χώρο εργασίας AI τώρα

Εγγραφείτε στο ενημερωτικό μας δελτίο για να ενημερώνεστε για νέες λειτουργίες και μελλοντικές κληρώσεις δώρων 👇