feat: sample data
This commit is contained in:
@@ -8,6 +8,7 @@ import {Create as $Create} from "@wailsio/runtime";
|
|||||||
export class Author {
|
export class Author {
|
||||||
"Id": number;
|
"Id": number;
|
||||||
"Name": string;
|
"Name": string;
|
||||||
|
"Posts": Post[];
|
||||||
|
|
||||||
/** Creates a new Author instance. */
|
/** Creates a new Author instance. */
|
||||||
constructor($$source: Partial<Author> = {}) {
|
constructor($$source: Partial<Author> = {}) {
|
||||||
@@ -17,6 +18,9 @@ export class Author {
|
|||||||
if (!("Name" in $$source)) {
|
if (!("Name" in $$source)) {
|
||||||
this["Name"] = "";
|
this["Name"] = "";
|
||||||
}
|
}
|
||||||
|
if (!("Posts" in $$source)) {
|
||||||
|
this["Posts"] = [];
|
||||||
|
}
|
||||||
|
|
||||||
Object.assign(this, $$source);
|
Object.assign(this, $$source);
|
||||||
}
|
}
|
||||||
@@ -25,7 +29,11 @@ export class Author {
|
|||||||
* Creates a new Author instance from a string or object.
|
* Creates a new Author instance from a string or object.
|
||||||
*/
|
*/
|
||||||
static createFrom($$source: any = {}): Author {
|
static createFrom($$source: any = {}): Author {
|
||||||
|
const $$createField2_0 = $$createType1;
|
||||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||||
|
if ("Posts" in $$parsedSource) {
|
||||||
|
$$parsedSource["Posts"] = $$createField2_0($$parsedSource["Posts"]);
|
||||||
|
}
|
||||||
return new Author($$parsedSource as Partial<Author>);
|
return new Author($$parsedSource as Partial<Author>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,7 +41,10 @@ export class Author {
|
|||||||
export class Post {
|
export class Post {
|
||||||
"Id": number;
|
"Id": number;
|
||||||
"Text": string;
|
"Text": string;
|
||||||
|
"Deadline": number;
|
||||||
"CreatedAt": number;
|
"CreatedAt": number;
|
||||||
|
"AuthorId": number;
|
||||||
|
"Author": Author;
|
||||||
|
|
||||||
/** Creates a new Post instance. */
|
/** Creates a new Post instance. */
|
||||||
constructor($$source: Partial<Post> = {}) {
|
constructor($$source: Partial<Post> = {}) {
|
||||||
@@ -43,9 +54,18 @@ export class Post {
|
|||||||
if (!("Text" in $$source)) {
|
if (!("Text" in $$source)) {
|
||||||
this["Text"] = "";
|
this["Text"] = "";
|
||||||
}
|
}
|
||||||
|
if (!("Deadline" in $$source)) {
|
||||||
|
this["Deadline"] = 0;
|
||||||
|
}
|
||||||
if (!("CreatedAt" in $$source)) {
|
if (!("CreatedAt" in $$source)) {
|
||||||
this["CreatedAt"] = 0;
|
this["CreatedAt"] = 0;
|
||||||
}
|
}
|
||||||
|
if (!("AuthorId" in $$source)) {
|
||||||
|
this["AuthorId"] = 0;
|
||||||
|
}
|
||||||
|
if (!("Author" in $$source)) {
|
||||||
|
this["Author"] = (new Author());
|
||||||
|
}
|
||||||
|
|
||||||
Object.assign(this, $$source);
|
Object.assign(this, $$source);
|
||||||
}
|
}
|
||||||
@@ -54,7 +74,16 @@ export class Post {
|
|||||||
* Creates a new Post instance from a string or object.
|
* Creates a new Post instance from a string or object.
|
||||||
*/
|
*/
|
||||||
static createFrom($$source: any = {}): Post {
|
static createFrom($$source: any = {}): Post {
|
||||||
|
const $$createField5_0 = $$createType2;
|
||||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||||
|
if ("Author" in $$parsedSource) {
|
||||||
|
$$parsedSource["Author"] = $$createField5_0($$parsedSource["Author"]);
|
||||||
|
}
|
||||||
return new Post($$parsedSource as Partial<Post>);
|
return new Post($$parsedSource as Partial<Post>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Private type creation functions
|
||||||
|
const $$createType0 = Post.createFrom;
|
||||||
|
const $$createType1 = $Create.Array($$createType0);
|
||||||
|
const $$createType2 = Author.createFrom;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export function Count(): Promise<number> & { cancel(): void } {
|
|||||||
|
|
||||||
export function Create(item: $models.Author): Promise<$models.Author> & { cancel(): void } {
|
export function Create(item: $models.Author): Promise<$models.Author> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(3684602449, item) as any;
|
let $resultPromise = $Call.ByID(3684602449, item) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType0($result);
|
return $$createType0($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||||
@@ -34,7 +34,7 @@ export function Delete(id: number): Promise<void> & { cancel(): void } {
|
|||||||
|
|
||||||
export function GetAll(): Promise<($models.Author | null)[]> & { cancel(): void } {
|
export function GetAll(): Promise<($models.Author | null)[]> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(3248293926) as any;
|
let $resultPromise = $Call.ByID(3248293926) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType2($result);
|
return $$createType2($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||||
@@ -43,7 +43,7 @@ export function GetAll(): Promise<($models.Author | null)[]> & { cancel(): void
|
|||||||
|
|
||||||
export function GetById(id: number): Promise<$models.Author | null> & { cancel(): void } {
|
export function GetById(id: number): Promise<$models.Author | null> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(1703016211, id) as any;
|
let $resultPromise = $Call.ByID(1703016211, id) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType1($result);
|
return $$createType1($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||||
@@ -52,7 +52,7 @@ export function GetById(id: number): Promise<$models.Author | null> & { cancel()
|
|||||||
|
|
||||||
export function Update(item: $models.Author): Promise<$models.Author> & { cancel(): void } {
|
export function Update(item: $models.Author): Promise<$models.Author> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(2240704960, item) as any;
|
let $resultPromise = $Call.ByID(2240704960, item) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType0($result);
|
return $$createType0($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export function Count(): Promise<number> & { cancel(): void } {
|
|||||||
|
|
||||||
export function Create(item: $models.Post): Promise<$models.Post> & { cancel(): void } {
|
export function Create(item: $models.Post): Promise<$models.Post> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(1443399856, item) as any;
|
let $resultPromise = $Call.ByID(1443399856, item) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType0($result);
|
return $$createType0($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||||
@@ -39,7 +39,7 @@ export function ExportToExcel(): Promise<void> & { cancel(): void } {
|
|||||||
|
|
||||||
export function GetAll(): Promise<($models.Post | null)[]> & { cancel(): void } {
|
export function GetAll(): Promise<($models.Post | null)[]> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(65691059) as any;
|
let $resultPromise = $Call.ByID(65691059) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType2($result);
|
return $$createType2($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||||
@@ -48,7 +48,7 @@ export function GetAll(): Promise<($models.Post | null)[]> & { cancel(): void }
|
|||||||
|
|
||||||
export function GetById(id: number): Promise<$models.Post | null> & { cancel(): void } {
|
export function GetById(id: number): Promise<$models.Post | null> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(4074736792, id) as any;
|
let $resultPromise = $Call.ByID(4074736792, id) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType1($result);
|
return $$createType1($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||||
@@ -57,7 +57,7 @@ export function GetById(id: number): Promise<$models.Post | null> & { cancel():
|
|||||||
|
|
||||||
export function Update(item: $models.Post): Promise<$models.Post> & { cancel(): void } {
|
export function Update(item: $models.Post): Promise<$models.Post> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(137798821, item) as any;
|
let $resultPromise = $Call.ByID(137798821, item) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType0($result);
|
return $$createType0($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import PostScheme from './post/PostScheme.vue';
|
import PostScheme from './post/PostScheme.vue';
|
||||||
|
import AuthorScheme from "./author/AuthorScheme.vue";
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<main class="w-screen h-screen">
|
<main class="w-screen h-screen">
|
||||||
<PostScheme />
|
<PostScheme />
|
||||||
|
<AuthorScheme />
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Table from '../table/Table.vue'
|
import Table from '../table/Table.vue'
|
||||||
import {onMounted, reactive} from 'vue'
|
import {onMounted, reactive} from 'vue'
|
||||||
import { getDefaultValues } from '../utils/structs/defaults.util.ts'
|
import {getDefaultValues} from '../utils/structs/defaults.util'
|
||||||
import S from './author.service.ts'
|
import Service from './author.service.ts'
|
||||||
import type {Scheme} from '../types/scheme.type'
|
import type {Scheme} from '../types/scheme.type'
|
||||||
import { Author } from '../../bindings/app/internal/services/models.ts'
|
import {Author} from '../../bindings/app/internal/services'
|
||||||
|
|
||||||
const service = new S
|
import PostService from '../post/post.service.ts'
|
||||||
|
|
||||||
|
const postService = new PostService
|
||||||
|
|
||||||
|
|
||||||
|
const service = new Service
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
(scheme as any).Posts.type!.nested!.values = await postService.readAll()
|
||||||
|
console.log(scheme)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const scheme: Scheme<Author> = reactive({
|
const scheme: Scheme<Author> = reactive({
|
||||||
Id: {
|
Id: {
|
||||||
hidden: true,
|
hidden: true,
|
||||||
@@ -20,6 +25,7 @@ Id:{
|
|||||||
primitive: "number",
|
primitive: "number",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
Name: {
|
Name: {
|
||||||
russian: "Имя",
|
russian: "Имя",
|
||||||
type: {
|
type: {
|
||||||
@@ -27,6 +33,17 @@ Name:{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Posts: {
|
||||||
|
russian: "Посты",
|
||||||
|
many: true,
|
||||||
|
type: {
|
||||||
|
nested: {
|
||||||
|
values: [],
|
||||||
|
field: ['Text']
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const getDefaults = () => getDefaultValues(scheme)
|
const getDefaults = () => getDefaultValues(scheme)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { GetAll, Create, Delete, GetById, Update, Count } from "../../bindings/app/internal/services/authorservice.ts"
|
import { GetAll, Create, Delete, GetById, Update, Count } from "../../bindings/app/internal/services/authorservice.ts"
|
||||||
import type { Author } from "../../bindings/app/internal/services/models.ts"
|
import type { Author } from "../../bindings/app/internal/services"
|
||||||
import type { IService } from "../types/service.type.ts"
|
import type { IService } from "../types/service.type.ts"
|
||||||
|
|
||||||
export default class AuthorService implements IService<Author> {
|
export default class AuthorService implements IService<Author> {
|
||||||
|
|||||||
@@ -1,37 +1,69 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Table from '../table/Table.vue'
|
import Table from '../table/Table.vue'
|
||||||
import { onMounted, reactive } from 'vue'
|
import { onMounted, reactive } from 'vue'
|
||||||
import { getDefaultValues } from '../utils/structs/defaults.util.ts'
|
import { getDefaultValues } from '../utils/structs/defaults.util'
|
||||||
import S from './post.service.ts'
|
import Service from './post.service.ts'
|
||||||
import type { Scheme } from '../types/scheme.type'
|
import type { Scheme } from '../types/scheme.type'
|
||||||
import { Post } from '../../bindings/app/internal/services/models.ts'
|
import { Post } from '../../bindings/app/internal/services'
|
||||||
|
|
||||||
const service = new S
|
import AuthorService from '../author/author.service.ts'
|
||||||
|
const authorService = new AuthorService
|
||||||
|
|
||||||
|
|
||||||
|
const service = new Service
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
|
||||||
|
(scheme as any).Author.type!.nested!.values = await authorService.readAll()
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const scheme: Scheme<Post> = reactive({
|
const scheme: Scheme<Post> = reactive({
|
||||||
|
|
||||||
Id: {
|
Id: {
|
||||||
hidden: true,
|
hidden: true,
|
||||||
type: {
|
type: {
|
||||||
primitive: "number",
|
primitive: "number",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
Text: {
|
Text: {
|
||||||
russian: "Текст",
|
russian: "Текст",
|
||||||
type: {
|
type: {
|
||||||
primitive: "string",
|
primitive: "string",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Deadline: {
|
||||||
|
russian: "Дедлайн",
|
||||||
|
type: {
|
||||||
|
primitive: "number",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
CreatedAt: {
|
CreatedAt: {
|
||||||
hidden: true,
|
hidden: true,
|
||||||
type: {
|
type: {
|
||||||
primitive: "number",
|
primitive: "number",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
AuthorId: {
|
||||||
|
type: {
|
||||||
|
primitive: "number",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
Author: {
|
||||||
|
russian: "Автор",
|
||||||
|
type: {
|
||||||
|
nested: {
|
||||||
|
values: [],
|
||||||
|
field: ['Name']
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const getDefaults = () => getDefaultValues(scheme)
|
const getDefaults = () => getDefaultValues(scheme)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { GetAll, Create, Delete, GetById, Update, Count } from "../../bindings/app/internal/services/postservice.ts"
|
import { GetAll, Create, Delete, GetById, Update, Count } from "../../bindings/app/internal/services/postservice.ts"
|
||||||
import type { Post } from "../../bindings/app/internal/services/models.ts"
|
import type { Post } from "../../bindings/app/internal/services"
|
||||||
import type { IService } from "../types/service.type.ts"
|
import type { IService } from "../types/service.type.ts"
|
||||||
|
|
||||||
export default class PostService implements IService<Post> {
|
export default class PostService implements IService<Post> {
|
||||||
|
|||||||
@@ -28,6 +28,24 @@ func newAuthor(db *gorm.DB, opts ...gen.DOOption) author {
|
|||||||
_author.ALL = field.NewAsterisk(tableName)
|
_author.ALL = field.NewAsterisk(tableName)
|
||||||
_author.Id = field.NewUint(tableName, "id")
|
_author.Id = field.NewUint(tableName, "id")
|
||||||
_author.Name = field.NewString(tableName, "name")
|
_author.Name = field.NewString(tableName, "name")
|
||||||
|
_author.Posts = authorHasManyPosts{
|
||||||
|
db: db.Session(&gorm.Session{}),
|
||||||
|
|
||||||
|
RelationField: field.NewRelation("Posts", "models.Post"),
|
||||||
|
Author: struct {
|
||||||
|
field.RelationField
|
||||||
|
Posts struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Posts.Author", "models.Author"),
|
||||||
|
Posts: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Posts.Author.Posts", "models.Post"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
_author.fillFieldMap()
|
_author.fillFieldMap()
|
||||||
|
|
||||||
@@ -40,6 +58,7 @@ type author struct {
|
|||||||
ALL field.Asterisk
|
ALL field.Asterisk
|
||||||
Id field.Uint
|
Id field.Uint
|
||||||
Name field.String
|
Name field.String
|
||||||
|
Posts authorHasManyPosts
|
||||||
|
|
||||||
fieldMap map[string]field.Expr
|
fieldMap map[string]field.Expr
|
||||||
}
|
}
|
||||||
@@ -74,9 +93,10 @@ func (a *author) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *author) fillFieldMap() {
|
func (a *author) fillFieldMap() {
|
||||||
a.fieldMap = make(map[string]field.Expr, 2)
|
a.fieldMap = make(map[string]field.Expr, 3)
|
||||||
a.fieldMap["id"] = a.Id
|
a.fieldMap["id"] = a.Id
|
||||||
a.fieldMap["name"] = a.Name
|
a.fieldMap["name"] = a.Name
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a author) clone(db *gorm.DB) author {
|
func (a author) clone(db *gorm.DB) author {
|
||||||
@@ -89,6 +109,84 @@ func (a author) replaceDB(db *gorm.DB) author {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type authorHasManyPosts struct {
|
||||||
|
db *gorm.DB
|
||||||
|
|
||||||
|
field.RelationField
|
||||||
|
|
||||||
|
Author struct {
|
||||||
|
field.RelationField
|
||||||
|
Posts struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a authorHasManyPosts) Where(conds ...field.Expr) *authorHasManyPosts {
|
||||||
|
if len(conds) == 0 {
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
exprs := make([]clause.Expression, 0, len(conds))
|
||||||
|
for _, cond := range conds {
|
||||||
|
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||||
|
}
|
||||||
|
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a authorHasManyPosts) WithContext(ctx context.Context) *authorHasManyPosts {
|
||||||
|
a.db = a.db.WithContext(ctx)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a authorHasManyPosts) Session(session *gorm.Session) *authorHasManyPosts {
|
||||||
|
a.db = a.db.Session(session)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a authorHasManyPosts) Model(m *models.Author) *authorHasManyPostsTx {
|
||||||
|
return &authorHasManyPostsTx{a.db.Model(m).Association(a.Name())}
|
||||||
|
}
|
||||||
|
|
||||||
|
type authorHasManyPostsTx struct{ tx *gorm.Association }
|
||||||
|
|
||||||
|
func (a authorHasManyPostsTx) Find() (result []*models.Post, err error) {
|
||||||
|
return result, a.tx.Find(&result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a authorHasManyPostsTx) Append(values ...*models.Post) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Append(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a authorHasManyPostsTx) Replace(values ...*models.Post) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Replace(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a authorHasManyPostsTx) Delete(values ...*models.Post) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Delete(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a authorHasManyPostsTx) Clear() error {
|
||||||
|
return a.tx.Clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a authorHasManyPostsTx) Count() int64 {
|
||||||
|
return a.tx.Count()
|
||||||
|
}
|
||||||
|
|
||||||
type authorDo struct{ gen.DO }
|
type authorDo struct{ gen.DO }
|
||||||
|
|
||||||
type IAuthorDo interface {
|
type IAuthorDo interface {
|
||||||
|
|||||||
@@ -28,7 +28,27 @@ func newPost(db *gorm.DB, opts ...gen.DOOption) post {
|
|||||||
_post.ALL = field.NewAsterisk(tableName)
|
_post.ALL = field.NewAsterisk(tableName)
|
||||||
_post.Id = field.NewUint(tableName, "id")
|
_post.Id = field.NewUint(tableName, "id")
|
||||||
_post.Text = field.NewString(tableName, "text")
|
_post.Text = field.NewString(tableName, "text")
|
||||||
|
_post.Deadline = field.NewInt64(tableName, "deadline")
|
||||||
_post.CreatedAt = field.NewInt64(tableName, "created_at")
|
_post.CreatedAt = field.NewInt64(tableName, "created_at")
|
||||||
|
_post.AuthorId = field.NewUint(tableName, "author_id")
|
||||||
|
_post.Author = postBelongsToAuthor{
|
||||||
|
db: db.Session(&gorm.Session{}),
|
||||||
|
|
||||||
|
RelationField: field.NewRelation("Author", "models.Author"),
|
||||||
|
Posts: struct {
|
||||||
|
field.RelationField
|
||||||
|
Author struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Author.Posts", "models.Post"),
|
||||||
|
Author: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Author.Posts.Author", "models.Author"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
_post.fillFieldMap()
|
_post.fillFieldMap()
|
||||||
|
|
||||||
@@ -41,7 +61,10 @@ type post struct {
|
|||||||
ALL field.Asterisk
|
ALL field.Asterisk
|
||||||
Id field.Uint
|
Id field.Uint
|
||||||
Text field.String
|
Text field.String
|
||||||
|
Deadline field.Int64
|
||||||
CreatedAt field.Int64
|
CreatedAt field.Int64
|
||||||
|
AuthorId field.Uint
|
||||||
|
Author postBelongsToAuthor
|
||||||
|
|
||||||
fieldMap map[string]field.Expr
|
fieldMap map[string]field.Expr
|
||||||
}
|
}
|
||||||
@@ -60,7 +83,9 @@ func (p *post) updateTableName(table string) *post {
|
|||||||
p.ALL = field.NewAsterisk(table)
|
p.ALL = field.NewAsterisk(table)
|
||||||
p.Id = field.NewUint(table, "id")
|
p.Id = field.NewUint(table, "id")
|
||||||
p.Text = field.NewString(table, "text")
|
p.Text = field.NewString(table, "text")
|
||||||
|
p.Deadline = field.NewInt64(table, "deadline")
|
||||||
p.CreatedAt = field.NewInt64(table, "created_at")
|
p.CreatedAt = field.NewInt64(table, "created_at")
|
||||||
|
p.AuthorId = field.NewUint(table, "author_id")
|
||||||
|
|
||||||
p.fillFieldMap()
|
p.fillFieldMap()
|
||||||
|
|
||||||
@@ -77,10 +102,13 @@ func (p *post) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *post) fillFieldMap() {
|
func (p *post) fillFieldMap() {
|
||||||
p.fieldMap = make(map[string]field.Expr, 3)
|
p.fieldMap = make(map[string]field.Expr, 6)
|
||||||
p.fieldMap["id"] = p.Id
|
p.fieldMap["id"] = p.Id
|
||||||
p.fieldMap["text"] = p.Text
|
p.fieldMap["text"] = p.Text
|
||||||
|
p.fieldMap["deadline"] = p.Deadline
|
||||||
p.fieldMap["created_at"] = p.CreatedAt
|
p.fieldMap["created_at"] = p.CreatedAt
|
||||||
|
p.fieldMap["author_id"] = p.AuthorId
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p post) clone(db *gorm.DB) post {
|
func (p post) clone(db *gorm.DB) post {
|
||||||
@@ -93,6 +121,84 @@ func (p post) replaceDB(db *gorm.DB) post {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type postBelongsToAuthor struct {
|
||||||
|
db *gorm.DB
|
||||||
|
|
||||||
|
field.RelationField
|
||||||
|
|
||||||
|
Posts struct {
|
||||||
|
field.RelationField
|
||||||
|
Author struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a postBelongsToAuthor) Where(conds ...field.Expr) *postBelongsToAuthor {
|
||||||
|
if len(conds) == 0 {
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
exprs := make([]clause.Expression, 0, len(conds))
|
||||||
|
for _, cond := range conds {
|
||||||
|
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||||
|
}
|
||||||
|
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a postBelongsToAuthor) WithContext(ctx context.Context) *postBelongsToAuthor {
|
||||||
|
a.db = a.db.WithContext(ctx)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a postBelongsToAuthor) Session(session *gorm.Session) *postBelongsToAuthor {
|
||||||
|
a.db = a.db.Session(session)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a postBelongsToAuthor) Model(m *models.Post) *postBelongsToAuthorTx {
|
||||||
|
return &postBelongsToAuthorTx{a.db.Model(m).Association(a.Name())}
|
||||||
|
}
|
||||||
|
|
||||||
|
type postBelongsToAuthorTx struct{ tx *gorm.Association }
|
||||||
|
|
||||||
|
func (a postBelongsToAuthorTx) Find() (result *models.Author, err error) {
|
||||||
|
return result, a.tx.Find(&result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a postBelongsToAuthorTx) Append(values ...*models.Author) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Append(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a postBelongsToAuthorTx) Replace(values ...*models.Author) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Replace(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a postBelongsToAuthorTx) Delete(values ...*models.Author) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Delete(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a postBelongsToAuthorTx) Clear() error {
|
||||||
|
return a.tx.Clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a postBelongsToAuthorTx) Count() int64 {
|
||||||
|
return a.tx.Count()
|
||||||
|
}
|
||||||
|
|
||||||
type postDo struct{ gen.DO }
|
type postDo struct{ gen.DO }
|
||||||
|
|
||||||
type IPostDo interface {
|
type IPostDo interface {
|
||||||
|
|||||||
@@ -7,10 +7,16 @@ var Entities = []any{
|
|||||||
type Post struct {
|
type Post struct {
|
||||||
Id uint `gorm:"primaryKey" ui:"hidden"`
|
Id uint `gorm:"primaryKey" ui:"hidden"`
|
||||||
Text string `displayName:"Текст" ui:"label=Текст"`
|
Text string `displayName:"Текст" ui:"label=Текст"`
|
||||||
|
Deadline int64 `ui:"label=Дедлайн"`
|
||||||
CreatedAt int64 `gorm:"autoCreateTime" ui:"hidden"`
|
CreatedAt int64 `gorm:"autoCreateTime" ui:"hidden"`
|
||||||
|
AuthorId uint
|
||||||
|
Author Author `ui:"label=Автор, data=Author, field=[Name]"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Author struct {
|
type Author struct {
|
||||||
Id uint `gorm:"primaryKey" ui:"hidden"`
|
Id uint `gorm:"primaryKey" ui:"hidden"`
|
||||||
Name string `ui:"label=Имя"`
|
Name string `ui:"label=Имя"`
|
||||||
|
Posts []Post `ui:"label=Посты, data=Post, field=[Text]"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: correct processing the semicolon (get attention to quotes)
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package services
|
|||||||
import (
|
import (
|
||||||
"app/internal/dialogs"
|
"app/internal/dialogs"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InsertDefaultData() {
|
func InsertDefaultData() {
|
||||||
insertPosts()
|
|
||||||
insertAuthors()
|
insertAuthors()
|
||||||
|
insertPosts()
|
||||||
}
|
}
|
||||||
|
|
||||||
func InsertDefaultEntityData[T any](service Service[T], entities []T) {
|
func InsertDefaultEntityData[T any](service Service[T], entities []T) {
|
||||||
@@ -24,14 +25,20 @@ func insertPosts() {
|
|||||||
{
|
{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
Text: "Жителям Кузбасса запретили болеть.",
|
Text: "Жителям Кузбасса запретили болеть.",
|
||||||
|
Deadline: time.Now().Unix(),
|
||||||
|
AuthorId: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Id: 2,
|
Id: 2,
|
||||||
|
Deadline: time.Now().Add(time.Hour * 24 * 5).Unix(),
|
||||||
Text: "⚡️⚡️⚡️Дома будут летать.",
|
Text: "⚡️⚡️⚡️Дома будут летать.",
|
||||||
|
AuthorId: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Id: 3,
|
Id: 3,
|
||||||
|
Deadline: time.Now().Add(time.Hour * 24 * 6).Unix(),
|
||||||
Text: "В Кузбассе начали строить дома выше, чтобы жители были ближе к богу и солнцу.",
|
Text: "В Кузбассе начали строить дома выше, чтобы жители были ближе к богу и солнцу.",
|
||||||
|
AuthorId: 3,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -42,5 +49,13 @@ func insertAuthors() {
|
|||||||
Id: 1,
|
Id: 1,
|
||||||
Name: "ИА Кузбасс",
|
Name: "ИА Кузбасс",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Id: 2,
|
||||||
|
Name: "ASTRA",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Id: 3,
|
||||||
|
Name: "ЧТД",
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
18
package-lock.json
generated
Normal file
18
package-lock.json
generated
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "boilerplate",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"dependencies": {
|
||||||
|
"@wailsio/runtime": "3.0.0-alpha.66"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@wailsio/runtime": {
|
||||||
|
"version": "3.0.0-alpha.66",
|
||||||
|
"resolved": "https://registry.npmjs.org/@wailsio/runtime/-/runtime-3.0.0-alpha.66.tgz",
|
||||||
|
"integrity": "sha512-ENLu8rn1griL1gFHJqkq1i+BVxrrA0JPJHYneUJYuf/s54kjuQViW0RKDEe/WTDo56ABpfykrd/T8OYpPUyXUw==",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user