mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
wip
This commit is contained in:
parent
d1cc5df7c5
commit
ba04122263
@ -2,6 +2,8 @@ import { isString } from 'lodash/fp';
|
||||
import type { Database } from '..';
|
||||
import type { ID } from '../types';
|
||||
|
||||
export type Repository = ReturnType<typeof createRepository>;
|
||||
|
||||
type Params = Record<string, unknown>;
|
||||
type Data = Record<string, unknown>;
|
||||
type Entity = {
|
||||
|
||||
@ -29,7 +29,7 @@ import { mapAsync } from '@strapi/utils';
|
||||
import * as types from '../utils/types';
|
||||
import { createField } from '../fields';
|
||||
import { createQueryBuilder } from '../query';
|
||||
import { createRepository } from './entity-repository';
|
||||
import { createRepository, Repository } from './entity-repository';
|
||||
import { deleteRelatedMorphOneRelationsAfterMorphToManyUpdate } from './morph-relations';
|
||||
import {
|
||||
isPolymorphic,
|
||||
@ -55,6 +55,8 @@ import type { Database } from '..';
|
||||
import type { Meta } from '../metadata';
|
||||
import type { ID } from '../types';
|
||||
|
||||
export type EntityManager = ReturnType<typeof createEntityManager>;
|
||||
|
||||
type Params = {
|
||||
where?: any;
|
||||
filters?: any;
|
||||
@ -257,7 +259,7 @@ const processData = (
|
||||
};
|
||||
|
||||
export const createEntityManager = (db: Database) => {
|
||||
const repoMap: Record<string, any> = {};
|
||||
const repoMap: Record<string, Repository> = {};
|
||||
|
||||
return {
|
||||
async findOne(uid: string, params: Params) {
|
||||
@ -1502,9 +1504,5 @@ export const createEntityManager = (db: Database) => {
|
||||
|
||||
return repoMap[uid];
|
||||
},
|
||||
|
||||
clearRepositories() {
|
||||
repoMap.clear();
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
import { Dialect, getDialect } from './dialects';
|
||||
import { createSchemaProvider } from './schema';
|
||||
import { createSchemaProvider, SchemaProvider } from './schema';
|
||||
import { createMetadata, Metadata } from './metadata';
|
||||
import { createEntityManager } from './entity-manager';
|
||||
import { createMigrationsProvider } from './migrations';
|
||||
import { createLifecyclesProvider } from './lifecycles';
|
||||
import { createEntityManager, EntityManager } from './entity-manager';
|
||||
import { createMigrationsProvider, MigrationProvider } from './migrations';
|
||||
import { createLifecyclesProvider, LifecycleProvider } from './lifecycles';
|
||||
import { createConnection } from './connection';
|
||||
import * as errors from './errors';
|
||||
import { Callback, transactionCtx } from './transaction-context';
|
||||
@ -36,17 +36,21 @@ class Database {
|
||||
|
||||
metadata: Metadata;
|
||||
|
||||
schema: ReturnType<typeof createSchemaProvider>;
|
||||
schema: SchemaProvider;
|
||||
|
||||
migrations: ReturnType<typeof createMigrationsProvider>;
|
||||
migrations: MigrationProvider;
|
||||
|
||||
lifecycles: ReturnType<typeof createLifecyclesProvider>;
|
||||
lifecycles: LifecycleProvider;
|
||||
|
||||
entityManager: ReturnType<typeof createEntityManager>;
|
||||
entityManager: EntityManager;
|
||||
|
||||
static transformContentTypes: typeof transformContentTypes;
|
||||
static transformContentTypes = transformContentTypes;
|
||||
|
||||
static init: (config: DatabaseConfig) => Promise<Database>;
|
||||
static async init(config: DatabaseConfig) {
|
||||
const db = new Database(config);
|
||||
await validateDatabase(db);
|
||||
return db;
|
||||
}
|
||||
|
||||
constructor(config: DatabaseConfig) {
|
||||
this.metadata = createMetadata(config.models);
|
||||
@ -160,12 +164,4 @@ class Database {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: move into strapi
|
||||
Database.transformContentTypes = transformContentTypes;
|
||||
Database.init = async (config: DatabaseConfig) => {
|
||||
const db = new Database(config);
|
||||
await validateDatabase(db);
|
||||
return db;
|
||||
};
|
||||
|
||||
export { Database, errors };
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
interface Attribute {
|
||||
import type { Model } from '../types';
|
||||
|
||||
export interface Attribute {
|
||||
type: string;
|
||||
multiple?: boolean;
|
||||
}
|
||||
|
||||
interface ContentType {
|
||||
export interface ContentType {
|
||||
uid: string;
|
||||
modelName: string;
|
||||
collectionName: string;
|
||||
attributes: Record<string, Attribute>;
|
||||
@ -26,7 +29,7 @@ const transformAttribute = (attribute: Attribute) => {
|
||||
};
|
||||
|
||||
// TODO: model logic outside DB
|
||||
export const transformContentTypes = (contentTypes: ContentType[]) => {
|
||||
export const transformContentTypes = (contentTypes: ContentType[]): Model[] => {
|
||||
return contentTypes.map((contentType) => {
|
||||
const model = {
|
||||
...contentType,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user