Compare commits
2 Commits
7449e7dc10
...
c402c775a3
Author | SHA1 | Date | |
---|---|---|---|
c402c775a3 | |||
87f5471b76 |
16
doc/TODO.txt
Normal file
16
doc/TODO.txt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
TODO: auto-timestamps
|
||||||
|
- SaveXyz should set created_at and updated_at; shouldn't touch is_deleted or deleted_at
|
||||||
|
- if soft delete is enabled, DeleteXyz should do update (not delete) and set is_deleted and deleted_at
|
||||||
|
- SaveXyz shouldn't set created_at in the do-update branch
|
||||||
|
- DeleteXyz should have pointer receiver
|
||||||
|
- GetXyzByID should include `ErrItemIsDeleted` if item is soft-deleted
|
||||||
|
|
||||||
|
TODO: primary-key
|
||||||
|
- SaveXyz shouldn't set primary key if it's rowid
|
||||||
|
|
||||||
|
TODO: foreign-key
|
||||||
|
- Generated types should match foreign keys to the type of the column they point to
|
||||||
|
|
||||||
|
TODO: modified-timestamps
|
||||||
|
- set updated_at and created_at in SaveXYZ
|
||||||
|
- soft delete option
|
122
doc/info.txt
Normal file
122
doc/info.txt
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
# GAS stack
|
||||||
|
|
||||||
|
## Concepts
|
||||||
|
|
||||||
|
- explict `schema.sql`
|
||||||
|
- solid-state applications
|
||||||
|
- no Docker
|
||||||
|
- https://git.tnd.gg/tnd/remichat/pulls/4#issuecomment-1218
|
||||||
|
- no environment split ("prod" vs "dev")
|
||||||
|
- environment distinctions are provided by scripts that call the application, not by the application
|
||||||
|
- try to avoid config files-- use shell scripts that pass flags instead
|
||||||
|
- put all the config variable values for a certain environment in that environment's runner context:
|
||||||
|
- values that are specific to Docker setups should go in docker-compose
|
||||||
|
- values that are for non-docker dev, maybe in .env or a runner shell script, or something like this
|
||||||
|
- assume that config values are finalized (i.e., don't need to be checked configVal == "" ? "default" : configVal) as high in the stack as possible (and also ensure this is the case). Ideally, vite.config.ts and onward already shouldn't need to do any val || "default" checking, and can simply accept env.PORT_NUMBER or env.IS_LOGGING_ENABLED as-is (or at most, parsing string->int, etc).
|
||||||
|
- https://git.tnd.gg/tnd/remichat/pulls/38#issuecomment-1645
|
||||||
|
- no frontend-backend separation (CORS)
|
||||||
|
- minimal config
|
||||||
|
- avoid cascading configs and multiple layers of defaults (e.g., `{ XYZ: "prefix" + (upperlayer.XYZ || "DefaultValue"), ... }`)
|
||||||
|
|
||||||
|
- subcommands executables
|
||||||
|
- scriptable applications: anything that the application can do, can be done via command line (i.e., avoid web-only operations)
|
||||||
|
- config is passed as command-line args
|
||||||
|
- avoid config env-vars (magical)
|
||||||
|
- shell scripts as glue code
|
||||||
|
|
||||||
|
- sample data
|
||||||
|
- https://git.tnd.gg/tnd/remichat/pulls/65#issuecomment-2035
|
||||||
|
|
||||||
|
## SQLite and ROWID
|
||||||
|
|
||||||
|
Tables must be EITHER:
|
||||||
|
- `rowid integer primary key` as first column declaration; OR
|
||||||
|
- `without rowid`, i.e., a clustered index
|
||||||
|
|
||||||
|
Other primary key and rowid settings are supported by SQLite, but NOT by Gas Stack:
|
||||||
|
- implicit `rowid`
|
||||||
|
- alternate `integer primary key` column, i.e., rowid alias
|
||||||
|
- non-rowid `primary key` that isn't a clustered index (note that SQLite doesn't actually support this, it just pretends to; the declared `primary key` in this case is just a regular unique index)
|
||||||
|
|
||||||
|
This is enforced by the Gas Stack schema linter, and cannot be configured. Other Gas Stack schema tools assume one of these arrangements, and will not work right if it's not followed.
|
||||||
|
|
||||||
|
## What not to do
|
||||||
|
|
||||||
|
- "scripts" folder
|
||||||
|
- "bin" with shell scripts in it
|
||||||
|
- using HTTP PUT or PATCH
|
||||||
|
|
||||||
|
## App structure
|
||||||
|
|
||||||
|
- pkg/
|
||||||
|
- db/
|
||||||
|
- schema.sql
|
||||||
|
- db_connect.go (migrations, versions and associated funcs, sql_schema, DBCreate, DBConnect)
|
||||||
|
- db_connect_test.go
|
||||||
|
- test_utils/
|
||||||
|
- db_setup.go
|
||||||
|
- cmd/
|
||||||
|
- main.go (parameterize DB_FILENAME)
|
||||||
|
- doc/
|
||||||
|
- sample_data/
|
||||||
|
- mount.sh
|
||||||
|
- seed.sql
|
||||||
|
- data/
|
||||||
|
- .github/
|
||||||
|
- workflows/
|
||||||
|
- build.yml
|
||||||
|
- .gitignore (sample_data/data)
|
||||||
|
- .golangci.yaml
|
||||||
|
- README.md
|
||||||
|
- ARCHITECTURE.md
|
||||||
|
|
||||||
|
|
||||||
|
gas init:
|
||||||
|
- git init
|
||||||
|
- go mod init
|
||||||
|
Params:
|
||||||
|
- omit sqlite
|
||||||
|
- omit github workflow
|
||||||
|
- database filename
|
||||||
|
- go module name
|
||||||
|
- include HTTP? (pkg/web, templ)
|
||||||
|
- data directory or just db file
|
||||||
|
|
||||||
|
gas generate_boilerplate [db-table-name]:
|
||||||
|
- struct
|
||||||
|
- Save function
|
||||||
|
- Get[Type]ByID function
|
||||||
|
|
||||||
|
gas generate-web
|
||||||
|
- install templ
|
||||||
|
- echo "*_templ.go" >> .gitignore
|
||||||
|
- pkg/web
|
||||||
|
- server.go
|
||||||
|
- middlewares.go
|
||||||
|
|
||||||
|
- web/
|
||||||
|
- static/
|
||||||
|
- vendor/
|
||||||
|
- styles.css
|
||||||
|
- tpl/
|
||||||
|
- server.go
|
||||||
|
- middlewares.go
|
||||||
|
- static.go
|
||||||
|
|
||||||
|
|
||||||
|
gas generate-subcommand
|
||||||
|
|
||||||
|
Considerations:
|
||||||
|
- godoc
|
||||||
|
|
||||||
|
# Methodologies
|
||||||
|
|
||||||
|
- Timestamp type: store dates and times as int64 (unix millis)
|
||||||
|
- code tags: TODO, XXX, WTF, DUPE tags
|
||||||
|
- `go test -tags integration` for integration testing (slow tests)
|
||||||
|
- cobra commands
|
||||||
|
- sqlx
|
||||||
|
- :memory: databases for testing
|
||||||
|
- go-chi router
|
||||||
|
|
||||||
|
- No docker-compose
|
12
pkg/flowutils/flowutils.go
Normal file
12
pkg/flowutils/flowutils.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package flowutils
|
||||||
|
|
||||||
|
func PanicIf(err error) {
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Must[T any](val T, err error) T {
|
||||||
|
PanicIf(err)
|
||||||
|
return val
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user