[fabric/sqlite-store] Refactor collection references to use new model definitions
This commit is contained in:
parent
3c3ce276c0
commit
c38f74414b
@ -1,5 +1,5 @@
|
||||
import {
|
||||
defineCollection,
|
||||
defineModel,
|
||||
Field,
|
||||
isGreaterOrEqualTo,
|
||||
isGreaterThan,
|
||||
@ -13,7 +13,7 @@ import { describe, expect, test } from "@fabric/testing";
|
||||
import { filterToParams, filterToSQL } from "./filter-to-sql.ts";
|
||||
|
||||
describe("SQL where clause from filter options", () => {
|
||||
const col = defineCollection("users", {
|
||||
const col = defineModel("users", {
|
||||
name: Field.string(),
|
||||
age: Field.integer(),
|
||||
status: Field.string(),
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
// deno-lint-ignore-file no-explicit-any
|
||||
import {
|
||||
Collection,
|
||||
FieldDefinition,
|
||||
FILTER_OPTION_OPERATOR_SYMBOL,
|
||||
FILTER_OPTION_TYPE_SYMBOL,
|
||||
FILTER_OPTION_VALUE_SYMBOL,
|
||||
FilterOptions,
|
||||
FilterValue,
|
||||
Model,
|
||||
MultiFilterOption,
|
||||
SingleFilterOption,
|
||||
} from "@fabric/domain";
|
||||
@ -24,7 +24,7 @@ export function filterToSQL(filterOptions?: FilterOptions) {
|
||||
}
|
||||
|
||||
export function filterToParams(
|
||||
collection: Collection,
|
||||
collection: Model,
|
||||
filterOptions?: FilterOptions,
|
||||
) {
|
||||
if (!filterOptions) return {};
|
||||
@ -100,7 +100,7 @@ function getWhereFromKeyValue(
|
||||
}
|
||||
|
||||
function getParamsFromMultiFilterOption(
|
||||
collection: Collection,
|
||||
collection: Model,
|
||||
filterOptions: MultiFilterOption,
|
||||
) {
|
||||
return filterOptions.reduce(
|
||||
@ -115,7 +115,7 @@ function getParamsFromMultiFilterOption(
|
||||
}
|
||||
|
||||
function getParamsFromSingleFilterOption(
|
||||
collection: Collection,
|
||||
collection: Model,
|
||||
filterOptions: SingleFilterOption,
|
||||
opts: { postfix?: string } = {},
|
||||
) {
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { defineCollection, Field } from "@fabric/domain";
|
||||
import { defineModel, Field } from "@fabric/domain";
|
||||
import { describe, expect, test } from "@fabric/testing";
|
||||
import { modelToSql } from "./model-to-sql.ts";
|
||||
|
||||
describe("ModelToSQL", () => {
|
||||
const model = defineCollection("something", {
|
||||
const model = defineModel("something", {
|
||||
id: Field.uuid({ isPrimaryKey: true }),
|
||||
name: Field.string(),
|
||||
age: Field.integer(),
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// deno-lint-ignore-file no-explicit-any
|
||||
import { Variant, VariantTag } from "@fabric/core";
|
||||
import { Collection, FieldDefinition, getTargetKey } from "@fabric/domain";
|
||||
import { FieldDefinition, getTargetKey, Model } from "@fabric/domain";
|
||||
|
||||
type FieldSQLDefinitionMap = {
|
||||
[K in FieldDefinition[VariantTag]]: (
|
||||
@ -61,7 +61,7 @@ function modifiersFromOpts(field: FieldDefinition) {
|
||||
}
|
||||
|
||||
export function modelToSql(
|
||||
model: Collection<string, Record<string, FieldDefinition>>,
|
||||
model: Model<string, Record<string, FieldDefinition>>,
|
||||
) {
|
||||
const fields = Object.entries(model.fields)
|
||||
.map(([name, type]) => fieldDefinitionToSQL(name, type))
|
||||
|
||||
@ -23,7 +23,10 @@ export function recordToSQLKeyParams(record: Record<string, any>) {
|
||||
/**
|
||||
* Unfold a record into a string of it's keys separated by commas.
|
||||
*/
|
||||
export function recordToSQLParams(model: Model, record: Record<string, any>) {
|
||||
export function recordToSQLParams(
|
||||
model: Model,
|
||||
record: Record<string, any>,
|
||||
) {
|
||||
return Object.keys(record).reduce(
|
||||
(acc, key) => ({
|
||||
...acc,
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
// deno-lint-ignore-file no-explicit-any
|
||||
import { PosixDate, VariantTag } from "@fabric/core";
|
||||
import { Collection, FieldDefinition, FieldToType } from "@fabric/domain";
|
||||
import { FieldDefinition, FieldToType, Model } from "@fabric/domain";
|
||||
|
||||
export function transformRow(model: Collection) {
|
||||
export function transformRow(model: Model) {
|
||||
return (row: Record<string, any>) => {
|
||||
const result: Record<string, any> = {};
|
||||
for (const key in row) {
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
// deno-lint-ignore-file no-explicit-any
|
||||
import { AsyncResult, Keyof, Optional } from "@fabric/core";
|
||||
import {
|
||||
Collection,
|
||||
FilterOptions,
|
||||
Model,
|
||||
ModelSchema,
|
||||
OrderByOptions,
|
||||
SelectableQuery,
|
||||
@ -128,7 +128,7 @@ export class QueryBuilder<T> implements StoreQuery<T> {
|
||||
}
|
||||
|
||||
export function getSelectStatement(
|
||||
collection: Collection,
|
||||
collection: Model,
|
||||
query: StoreQueryDefinition,
|
||||
): [string, Record<string, any>] {
|
||||
const selectFields = query.keys ? query.keys.join(", ") : "*";
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { PosixDate, Run } from "@fabric/core";
|
||||
import { defineModel, Field, isLike, UUID } from "@fabric/domain";
|
||||
import { defineAggregateModel, Field, isLike, UUID } from "@fabric/domain";
|
||||
import { UUIDGeneratorMock } from "@fabric/domain/mocks";
|
||||
import {
|
||||
afterEach,
|
||||
@ -13,11 +13,11 @@ import { SQLiteStateStore } from "./state-store.ts";
|
||||
|
||||
describe("State Store", () => {
|
||||
const models = [
|
||||
defineModel("demo", {
|
||||
defineAggregateModel("demo", {
|
||||
value: Field.float(),
|
||||
owner: Field.reference({ targetModel: "users" }),
|
||||
}),
|
||||
defineModel("users", {
|
||||
defineAggregateModel("users", {
|
||||
name: Field.string(),
|
||||
}),
|
||||
];
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { AsyncResult, UnexpectedError } from "@fabric/core";
|
||||
import {
|
||||
Model,
|
||||
type Model,
|
||||
ModelSchemaFromModels,
|
||||
ModelToType,
|
||||
StoreQuery,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user