Skip to content

Commit

Permalink
docs: add new getting-started sections; some code reorg & fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Worm committed May 7, 2024
1 parent b28c0aa commit 20f06d3
Show file tree
Hide file tree
Showing 21 changed files with 1,070 additions and 68 deletions.
14 changes: 7 additions & 7 deletions docs/code/getting-started/code-generation/data.cue
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ package example
Input: {
User: {
Fields: {
id: Type: "int"
admin: Type: "bool"
id: Type: "int"
admin: Type: "bool"
username: Type: "string"
email: Type: "string"
email: Type: "string"
}
Relations: {
Profile: "HasOne"
Expand All @@ -21,16 +21,16 @@ Input: {
Profile: {
Fields: {
displayName: Type: "string"
status: Type: "string"
about: Type: "string"
status: Type: "string"
about: Type: "string"
}
Relations: User: "BelongsTo"
}

Post: {
Fields: {
title: Type: "string"
body: Type: "string"
title: Type: "string"
body: Type: "string"
public: Type: "bool"
}
Relations: User: "BelongsTo"
Expand Down
1 change: 1 addition & 0 deletions docs/code/getting-started/code-generation/gen.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 3 additions & 3 deletions docs/code/getting-started/code-generation/interlude.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Dougie",
"question": "Did you see all them turtles?",
"answer": "They went all the way down!"
"name": "Dougie",
"question": "Did you see all them turtles?",
"answer": "They went all the way down!"
}
4 changes: 2 additions & 2 deletions docs/code/getting-started/code-generation/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Input: #Input
// This is your input schema
#Input: {
// this is a CUE pattern to apply #Type to every key
[key=string]: #Type & {
[key=string]: #Type & {
// here we are enriching the input, mapping key -> Name
Name: key
}
Expand All @@ -20,7 +20,7 @@ Input: #Input

// This is a CUE pattern for a struct of structs
// you can set nested fields based on the key name in [key=string]
Fields: [field=string]: #Field & { Name: field }
Fields: [field=string]: #Field & {Name: field}

// Enum of relation types with the key being the Name of the other side
Relations: [other=string]: "BelongsTo" | "HasOne" | "HasMany" | "ManyToMany"
Expand Down
1 change: 1 addition & 0 deletions docs/code/getting-started/code-generation/type.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions docs/code/getting-started/code-generation/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

31 changes: 31 additions & 0 deletions docs/code/getting-started/data-layer/create/datamodel.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package datamodel

import (
"github.com/hofstadter-io/hof/schema/dm/sql"
"github.com/hofstadter-io/hof/schema/dm/fields"
)

// Traditional database model which maps onto tables & columns.
Datamodel: sql.Datamodel & {
Models: {
User: {
Fields: {
ID: fields.UUID
CreatedAt: fields.Datetime
UpdatedAt: fields.Datetime
DeletedAt: fields.Datetime

email: fields.Email
username: fields.String
password: fields.Password
verified: fields.Bool
active: fields.Bool

persona: fields.Enum & {
Vals: ["guest", "user", "admin", "owner"]
Default: "user"
}
}
}
}
}
236 changes: 236 additions & 0 deletions docs/code/getting-started/data-layer/create/hof-eval.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
// Traditional database model which maps onto tables & columns.
Datamodel: {
// schema for #hof: ...
#hof: {
// #hof version
apiVersion: "v1beta1"

// typical metadata
metadata: {}

// hof/datamodel
datamodel: {
// define the root of a datamodel
root: true

// instruct history to be tracked
history: true

// instruct ordrered version of the fields
// to be injected as a peer value
ordered: false

// tell hof this is a node of interest for
// the inspection commands (list,info)
node: false

// tell hof to track this as a raw CUE value
// (partially implemented)
cue: false
}
}
Snapshot: {
Timestamp: ""
}

// these are the models for the application
// they can map onto database tables and apis
Models: {
User: {
// for easy access
Name: "User"
Plural: "Users"

// These are the fields of a model
// they can map onto database columnts and form fields
Fields: {
ID: {
Name: "ID"
Plural: "IDs"
Type: "uuid"
Nullable: false
Unique: true
Validation: {
Format: "uuid"
}
#hof: {
metadata: {
name: "ID"
}
}
}
CreatedAt: {
Name: "CreatedAt"
Plural: "CreatedAts"
Type: "datetime"
#hof: {
metadata: {
name: "CreatedAt"
}
}
}
UpdatedAt: {
Name: "UpdatedAt"
Plural: "UpdatedAts"
Type: "datetime"
#hof: {
metadata: {
name: "UpdatedAt"
}
}
}
DeletedAt: {
Name: "DeletedAt"
Plural: "DeletedAts"
Type: "datetime"
#hof: {
metadata: {
name: "DeletedAt"
}
}
}
email: {
Name: "email"
Plural: "emails"
Type: "string"
Length: 64
Unique: true
Nullable: false
Validation: {
Max: 64
Format: "email"
}
#hof: {
metadata: {
name: "email"
}
}
}
username: {
Name: "username"
Plural: "usernames"
Type: "string"
Length: 64
Unique: false
Nullable: false
Validation: {
Max: 64
}
#hof: {
metadata: {
name: "username"
}
}
}
password: {
Name: "password"
Plural: "passwords"
Bcrypt: true
Type: "string"
Length: 64
Unique: false
Nullable: false
Validation: {
Max: 64
}
#hof: {
metadata: {
name: "password"
}
}
}
verified: {
Name: "verified"
Plural: "verifieds"
Type: "bool"
Default: "false"
Nullable: false
#hof: {
metadata: {
name: "verified"
}
}
}
active: {
Name: "active"
Plural: "actives"
Type: "bool"
Default: "false"
Nullable: false
#hof: {
metadata: {
name: "active"
}
}
}
persona: {
Name: "persona"
Plural: "personas"
Type: "string"
Vals: ["guest", "user", "admin", "owner"]
Nullable: false
Default: "user"
#hof: {
metadata: {
name: "persona"
}
}
}
#hof: {
datamodel: {
node: true
ordered: true
}
}
}

// if we want Relations as a separate value
// we can process the fields to extract them
// schema for #hof: ...
#hof: {
// #hof version
apiVersion: "v1beta1"

// typical metadata
metadata: {
name: "User"
}

// hof/datamodel
datamodel: {
// define the root of a datamodel
root: false

// instruct history to be tracked
history: true

// instruct ordrered version of the fields
// to be injected as a peer value
ordered: false

// tell hof this is a node of interest for
// the inspection commands (list,info)
node: false

// tell hof to track this as a raw CUE value
// (partially implemented)
cue: false
}
}
Snapshot: {
Timestamp: ""
}
History: []
}
#hof: {
datamodel: {
node: true
ordered: true
}
}
}

// OrderedModels: [...Model] will be
// inject here for order stability
History: []
}
57 changes: 57 additions & 0 deletions docs/code/getting-started/data-layer/update/datamodel.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package datamodel

import (
"github.com/hofstadter-io/hof/schema/dm/sql"
"github.com/hofstadter-io/hof/schema/dm/fields"
)

// Traditional database model which maps onto tables & columns.
Datamodel: sql.Datamodel & {
Models: {
User: {
Fields: {
ID: fields.UUID
CreatedAt: fields.Datetime
UpdatedAt: fields.Datetime
DeletedAt: fields.Datetime

email: fields.Email
username: fields.String
password: fields.Password
verified: fields.Bool
active: fields.Bool

persona: fields.Enum & {
Vals: ["guest", "user", "admin", "owner"]
Default: "user"
}

// relation fields
Profile: fields.UUID
Profile: Relation: {
Name: "Profile"
Type: "has-one"
Other: "Models.UserProfile"
}
}
}

UserProfile: {
Fields: {
// note how we are using sql fields here
sql.CommonFields

About: sql.Varchar
Avatar: sql.Varchar
Social: sql.Varchar

Owner: fields.UUID
Owner: Relation: {
Name: "Owner"
Type: "belongs-to"
Other: "Models.User"
}
}
}
}
}
Loading

0 comments on commit 20f06d3

Please sign in to comment.