Files
directus/packages/data
Nicola Krumschmidt 1aaf3fc218 Add support for filtering using a json object as target to durus (#21455)
* Add support for nested object target to abstract query

Co-authored-by: Jan Arends <jaads@users.noreply.github.com>

* Implement nested object target conversion

* added parameters in tests

* tiny refactoring

* test for json filter

* test and fix

* json value as filter target

* fixed mixed props and column name

* support for deeply nested filtering

* casting for filtering against numbers within a json

* another test

* linter fix

* split up set condition nodes

Co-authored-by: Nicola Krumschmidt <nickrum@users.noreply.github.com>

* added json target support for geo and set condition

Co-authored-by: Nicola Krumschmidt <nicola.krumschmidt@freenet.de>

* linter fixes

* reverted json target for geo condition

* test for comparing field with primitive

* removed geo condition test

* Fix type issue

* Remove double cast to integer

* Implement stringification of order by with json

* Fix spelling error

* Clean up field condition node stringification

* Cast numbers to numeric type instead of integer

* Implement stringification of json geo condition

* Flip around string condition type check

* Refactor number condition stringification

* Refactor set number condition stringification

* Refactor set string condition stringification

* Rename comparisonValue to compareValue for consistency

* test for geo condition with json target

* utility for target conversion

* Convert json target in order by node as object

* test for json target in order by

---------

Co-authored-by: Jan Arends <jaads@users.noreply.github.com>
Co-authored-by: Jan Arends <jan.arends@mailbox.org>
Co-authored-by: Nicola Krumschmidt <nickrum@users.noreply.github.com>
2024-02-28 14:40:11 +01:00
..
2023-05-10 14:30:53 -04:00
2023-09-26 21:14:27 +08:00

@directus/data

Warning

This is a work in progress. Nothing is expected to work yet.

Installation

npm install @directus/data

The installation of a driver is also required.

Usage

Setup

import { DataEngine } from '@directus/data';
import { DataDriverPostgres } from '@directus/data-driver-postgres';

// Instantiate the engine
const engine = new DataEngine();

// Instantiate a driver
const pgDriver = new DataDriverPostgres({
	connectionString: 'postgresql://root:password@localhost/mydb',
});

// register the driver to the engine
await engine.registerStore('postgres', pgDriver);

Query data

// query data
await engine.query({
	store: 'postgres',
	collection: 'articles',
	fields: [
		{
			type: 'primitive',
			field: 'id',
		},
	],
});

The above is resulting in the following flow.

graph TB;
    api --> data
	subgraph da[data abstraction]
		direction TB
		data --> data-driver-x --> db1[(datastore)]
		data --> data-driver-y --> db2[(datastore)]
	end

Current architecture of this package

To get an overview of how the package is organized regarding it's files, directories and the dependencies between them, run pnpm run depcruise and have a look in the created dependency-graph.svg image.