Skip to content

Commit

Permalink
Merge pull request #66 from CRBroughton/65-allow-char-to-specify-size
Browse files Browse the repository at this point in the history
65 allow char to specify size
  • Loading branch information
CRBroughton authored Apr 27, 2024
2 parents 48e7dc1 + 88e56f2 commit 183d9ee
Show file tree
Hide file tree
Showing 23 changed files with 96 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-candles-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@crbroughton/sibyl": minor
---

Improve support for char type - char type can now specify the size
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ createTable('firstTable', { // inferred table name and entry
},
name: {
type: 'char',
size: 4,
},
sex: {
type: 'char',
size: 3,
},
hasReadTheReadme: {
type: 'bool',
Expand Down
2 changes: 2 additions & 0 deletions src/bun/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ createTable('firstTable', { // inferred table name and entry
},
name: {
type: 'char',
size: 4,
},
sex: {
type: 'char',
size: 3,
},
hasReadTheReadme: {
type: 'bool',
Expand Down
6 changes: 6 additions & 0 deletions src/bun/tests/all.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ describe('all tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
})

Expand Down Expand Up @@ -75,9 +77,11 @@ describe('all tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
})

Expand Down Expand Up @@ -128,9 +132,11 @@ describe('all tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
})

Expand Down
2 changes: 2 additions & 0 deletions src/bun/tests/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ describe('create tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down
2 changes: 2 additions & 0 deletions src/bun/tests/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ describe('delete tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
})
Insert('first', [
Expand Down
12 changes: 12 additions & 0 deletions src/bun/tests/select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ describe('select tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down Expand Up @@ -70,9 +72,11 @@ describe('select tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down Expand Up @@ -128,9 +132,11 @@ describe('select tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down Expand Up @@ -199,9 +205,11 @@ describe('select tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down Expand Up @@ -268,9 +276,11 @@ describe('select tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down Expand Up @@ -345,12 +355,14 @@ describe('select tests', () => {
},
name: {
type: 'char',
size: 4,
},
hasReadTheReadme: {
type: 'bool',
},
location: {
type: 'char',
size: 8,
},
})

Expand Down
2 changes: 2 additions & 0 deletions src/bun/tests/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ describe('update tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down
2 changes: 2 additions & 0 deletions src/libsql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ createTable('firstTable', { // inferred table name and entry
},
name: {
type: 'char',
size: 4,
},
sex: {
type: 'char',
size: 3,
},
hasReadTheReadme: {
type: 'bool',
Expand Down
6 changes: 6 additions & 0 deletions src/libsql/tests/all.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ describe('all tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
})

Expand Down Expand Up @@ -75,9 +77,11 @@ describe('all tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
})

Expand Down Expand Up @@ -128,9 +132,11 @@ describe('all tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
})

Expand Down
2 changes: 2 additions & 0 deletions src/libsql/tests/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ describe('create tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down
2 changes: 2 additions & 0 deletions src/libsql/tests/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ describe('delete tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
})
Insert('first', [
Expand Down
12 changes: 12 additions & 0 deletions src/libsql/tests/select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ describe('select tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down Expand Up @@ -70,9 +72,11 @@ describe('select tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down Expand Up @@ -128,9 +132,11 @@ describe('select tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down Expand Up @@ -199,9 +205,11 @@ describe('select tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down Expand Up @@ -268,9 +276,11 @@ describe('select tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down Expand Up @@ -345,12 +355,14 @@ describe('select tests', () => {
},
name: {
type: 'char',
size: 4,
},
hasReadTheReadme: {
type: 'bool',
},
location: {
type: 'char',
size: 8,
},
})

Expand Down
2 changes: 2 additions & 0 deletions src/libsql/tests/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ describe('update tests', () => {
},
location: {
type: 'char',
size: 8,
},
name: {
type: 'char',
size: 4,
},
booleanTest: {
type: 'bool',
Expand Down
5 changes: 2 additions & 3 deletions src/sibylLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,14 @@ export function convertCreateTableStatement<T extends Record<string, any>>(obj:
for (const [columnName, columnType] of Object.entries<DBEntry<DBTypes>>(sortKeys([obj])[0])) {
result += columnName

if (columnType.type !== 'varchar' && columnType.type !== 'primary')
if (columnType.type !== 'varchar' && columnType.type !== 'char' && columnType.type !== 'primary')
result += ` ${columnType.type}`

if (columnType.type === 'primary')
result += ' INTEGER'

if (columnType.type === 'varchar' && 'size' in columnType)
if ((columnType.type === 'varchar' && 'size' in columnType) || (columnType.type === 'char' && 'size' in columnType))
result += ` ${columnType.type}(${columnType.size})`

if (columnType.type === 'primary')
result += processPrimaryType(columnType)
else
Expand Down
2 changes: 2 additions & 0 deletions src/sqljs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ createTable('firstTable', { // inferred table name and entry
},
name: {
type: 'char',
size: 4,
},
sex: {
type: 'char',
size: 3,
},
hasReadTheReadme: {
type: 'bool',
Expand Down
Loading

0 comments on commit 183d9ee

Please sign in to comment.