Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update sqlite to use a hand build schema #2305

Merged
merged 1 commit into from
Jan 17, 2025
Merged

feat: update sqlite to use a hand build schema #2305

merged 1 commit into from
Jan 17, 2025

Conversation

ozym
Copy link
Contributor

@ozym ozym commented Nov 27, 2024

This is the next iteration on from the basic table layout, there has been more effort in normalisation. There are still some outstanding issues, one improvement would be to consolidate some of the tables.

@ozym ozym requested review from a team as code owners November 27, 2024 10:12
@ozym ozym force-pushed the sqlite-v2 branch 2 times, most recently from 45de6c1 to 48467ed Compare November 27, 2024 10:20
@ozym ozym self-assigned this Nov 27, 2024
@ozym ozym added the do not merge Not quite ready for operations label Nov 27, 2024
@ozym ozym force-pushed the sqlite-v2 branch 2 times, most recently from 2979667 to c662385 Compare November 27, 2024 10:41
@ozym ozym added enhancement New feature development work and removed do not merge Not quite ready for operations labels Dec 20, 2024
@ardrigh
Copy link
Contributor

ardrigh commented Jan 15, 2025

@ozym I had a quick once over looking at the structs and a few of the sql queries where you might expect to call them, and it's not clear the sql queries are using the same field names.

eg query for start_time when the struct has start and end.

Are the fields being updated outside the structs before the sql queries are run?

@ozym
Copy link
Contributor Author

ozym commented Jan 15, 2025

@ozym I had a quick once over looking at the structs and a few of the sql queries where you might expect to call them, and it's not clear the sql queries are using the same field names.

eg query for start_time when the struct has start and end.

Are the fields being updated outside the structs before the sql queries are run?

If this is for the example code, then usually the mechanism is to do the SQL query (with the details of the schema) and then pass each resulting line into an extraction which then maps the order of the query output values into variable fields, which tend to be part of a struct.

e.g.

query := "SELECT make.make,sensor.start_date,sensor.end_date FROM <snip> WHERE <snip>";
then prepare this, so that when the query is run then the results will be scanned rows, where the "make" is in the first column, and in this case the start and end dates would be the second and third.

Then when you scan each row you can map them into a different structure, e.g.

type Sensor struct {
    Make string
    Start time.Time
    End time.Time
}

func() {
 ...
        sensors := make([]Sensor, 0)
        for results.Next() {
                var sensor Sensor

                if err := results.Scan(&sensor.Make, &sensor.Start, &sensor.End); err != nil {
                       error here.
                }

                sensors = append(sensors, sensor)
        }
...
}

etc.

@ozym
Copy link
Contributor Author

ozym commented Jan 15, 2025

For added context, I haven't tried to build an ORM in which case, yes the field names should map to sql values.

@ardrigh
Copy link
Contributor

ardrigh commented Jan 15, 2025

Cool thanks, I will have a proper read through

@ozym ozym force-pushed the sqlite-v2 branch 6 times, most recently from a2fc3be to 1a9c4ce Compare January 17, 2025 02:16
This is the next iteration on from the basic table layout, there has
been more effort in normalisation.  There are still some outstanding
issues, one improvement would be to consolidate some of the tables.
Copy link

@MCorfy MCorfy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@ozym ozym merged commit c82d20f into main Jan 17, 2025
18 checks passed
@ozym ozym deleted the sqlite-v2 branch January 17, 2025 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature development work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants