Bootstrap coredata object

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-01-22 10:57:09 +01:00
parent 0904426891
commit b749c1277a
6 changed files with 158 additions and 2 deletions

View File

@@ -0,0 +1,13 @@
package coredata
import "time"
type (
Control struct {
ID string
FrameworkID string
ContentID string
CreatedAt time.Time
UpdatedAt time.Time
}
)

View File

@@ -0,0 +1,13 @@
package coredata
import "time"
type (
Evidence struct {
ID string
TaskID string
ContentID string
CreatedAt time.Time
UpdatedAt time.Time
}
)

View File

@@ -0,0 +1,60 @@
package coredata
import (
"context"
"time"
"github.com/jackc/pgx/v5"
"go.gearno.de/kit/pg"
)
type (
Framework struct {
ID string
OrganizationID string
ContentID string
CreatedAt time.Time
UpdatedAt time.Time
}
)
func (f *Framework) scan(r pgx.Row) error {
return r.Scan(
&f.ID,
&f.OrganizationID,
&f.ContentID,
&f.CreatedAt,
&f.UpdatedAt,
)
}
func (f *Framework) LoadByID(
ctx context.Context,
conn pg.Conn,
frameworkID string,
) error {
q := `
SELECT
framework_id,
organization_id,
content_id,
created_at,
updated_at
FROM
frameworks
WHERE
framework_id = @framework_id
LIMIT 1;
`
args := pgx.NamedArgs{"framework_id": frameworkID}
r := conn.QueryRow(ctx, q, args)
f2 := Framework{}
if err := r.Scan(&f2); err != nil {
return err
}
*f = f2
return nil
}

View File

@@ -0,0 +1,58 @@
package coredata
import (
"context"
"time"
"github.com/jackc/pgx/v5"
"go.gearno.de/kit/pg"
)
type (
Organization struct {
ID string
Name string
CreatedAt time.Time
UpdatedAt time.Time
}
)
func (o *Organization) scan(r pgx.Row) error {
return r.Scan(
&o.ID,
&o.Name,
&o.CreatedAt,
&o.UpdatedAt,
)
}
func (o *Organization) LoadByID(
ctx context.Context,
conn pg.Conn,
organizationID string,
) error {
q := `
SELECT
organization_id,
name,
created_at,
updated_at
FROM
organizations
WHERE
organization_id = @organization_id
LIMIT 1;
`
args := pgx.NamedArgs{"organization_id": organizationID}
r := conn.QueryRow(ctx, q, args)
o2 := Organization{}
if err := r.Scan(&o2); err != nil {
return err
}
*o = o2
return nil
}

View File

@@ -0,0 +1,12 @@
package coredata
import "time"
type (
Task struct {
ID string
ContentID string
CreatedAt time.Time
UpdatedAt time.Time
}
)