create-absolutejs 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -24
- package/README.md +179 -179
- package/dist/commands/formatProject.js +3 -2
- package/dist/commands/initializeGit.js +1 -1
- package/dist/commands/installDependencies.js +4 -3
- package/dist/data.js +22 -21
- package/dist/generators/configurations/generateDrizzleConfig.js +15 -15
- package/dist/generators/configurations/generatePackageJson.js +25 -23
- package/dist/generators/configurations/generatePrettierrc.js +9 -9
- package/dist/generators/db/dockerInitTemplates.js +79 -79
- package/dist/generators/db/generateDatabaseTypes.js +6 -6
- package/dist/generators/db/generateDockerContainer.js +14 -14
- package/dist/generators/db/generateDrizzleSchema.js +17 -17
- package/dist/generators/db/generateSqliteSchema.js +8 -8
- package/dist/generators/db/handlerTemplates.js +259 -259
- package/dist/generators/db/scaffoldDocker.js +1 -1
- package/dist/generators/html/generateHTMLPage.js +60 -60
- package/dist/generators/htmx/generateHTMXPage.js +86 -86
- package/dist/generators/project/generateAbsoluteAuthConfig.d.ts +1 -1
- package/dist/generators/project/generateAbsoluteAuthConfig.js +100 -89
- package/dist/generators/project/generateDBBlock.js +9 -9
- package/dist/generators/project/generateMarkupCSS.js +145 -145
- package/dist/generators/project/generateRoutesBlock.d.ts +3 -2
- package/dist/generators/project/generateRoutesBlock.js +37 -36
- package/dist/generators/project/generateServer.js +22 -18
- package/dist/generators/project/scaffoldBackend.js +2 -1
- package/dist/generators/project/scaffoldFrontends.d.ts +2 -2
- package/dist/generators/project/scaffoldFrontends.js +5 -2
- package/dist/generators/react/generateReactComponents.js +95 -95
- package/dist/generators/svelte/generateSveltePage.js +210 -210
- package/dist/generators/vue/generateVuePage.js +261 -261
- package/dist/messages.js +43 -43
- package/dist/questions/projectName.js +1 -1
- package/dist/scaffold.js +2 -1
- package/dist/templates/README.md +35 -35
- package/dist/templates/assets/svg/google-logo.svg +7 -7
- package/dist/templates/assets/svg/htmx-logo-black.svg +9 -9
- package/dist/templates/assets/svg/htmx-logo-white.svg +9 -9
- package/dist/templates/assets/svg/vue-logo.svg +4 -4
- package/dist/templates/configurations/.prettierignore +3 -3
- package/dist/templates/configurations/.prettierrc.json +9 -9
- package/dist/templates/configurations/drizzle.config.ts +13 -13
- package/dist/templates/configurations/eslint.config.mjs +243 -243
- package/dist/templates/configurations/tsconfig.example.json +98 -98
- package/dist/templates/constants.ts +2 -2
- package/dist/templates/db/docker-compose.db.yml +15 -15
- package/dist/templates/git/gitignore +51 -51
- package/dist/templates/html/scripts/typescript-example.ts +21 -21
- package/dist/templates/react/components/App.tsx +52 -52
- package/dist/templates/react/components/Head.tsx +34 -34
- package/dist/templates/react/components/OAuthLink.tsx +39 -39
- package/dist/templates/react/components/ProfilePicture.tsx +56 -56
- package/dist/templates/styles/colors.ts +11 -11
- package/dist/templates/styles/reset.css +84 -84
- package/dist/templates/svelte/components/Counter.svelte +19 -19
- package/dist/templates/svelte/composables/counter.svelte.ts +14 -14
- package/dist/templates/tailwind/postcss.config.ts +8 -8
- package/dist/templates/tailwind/tailwind.config.ts +7 -7
- package/dist/templates/tailwind/tailwind.css +1 -1
- package/dist/templates/vue/components/CountButton.vue +39 -39
- package/dist/templates/vue/composables/useCount.ts +14 -14
- package/dist/utils/commandMaps.d.ts +1 -1
- package/dist/utils/commandMaps.js +4 -4
- package/dist/versions.d.ts +49 -0
- package/dist/versions.js +61 -0
- package/package.json +21 -20
- package/dist/templates/styles/tailwind.css +0 -1
|
@@ -1,322 +1,322 @@
|
|
|
1
|
-
const buildSqlAuthTemplate = ({ importLines, queries }) => `
|
|
2
|
-
import { DatabaseType, NewUser } from '../../types/databaseTypes';
|
|
3
|
-
${importLines}
|
|
4
|
-
|
|
5
|
-
export const getUser = async (db: DatabaseType, authSub: string) => {
|
|
6
|
-
${queries.selectUser}
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const createUser = async (db: DatabaseType, newUserData: NewUser) => {
|
|
10
|
-
${queries.insertUser}
|
|
1
|
+
const buildSqlAuthTemplate = ({ importLines, queries }) => `
|
|
2
|
+
import { DatabaseType, NewUser } from '../../types/databaseTypes';
|
|
3
|
+
${importLines}
|
|
4
|
+
|
|
5
|
+
export const getUser = async (db: DatabaseType, authSub: string) => {
|
|
6
|
+
${queries.selectUser}
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const createUser = async (db: DatabaseType, newUserData: NewUser) => {
|
|
10
|
+
${queries.insertUser}
|
|
11
11
|
}`;
|
|
12
|
-
const buildSqlCountTemplate = ({ importLines, dbType, queries }) => `
|
|
13
|
-
${importLines}
|
|
14
|
-
export const getCountHistory = async (db: ${dbType}, uid: number) => {
|
|
15
|
-
${queries.selectHistory}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const createCountHistory = async (db: ${dbType}, count: number) => {
|
|
19
|
-
${queries.insertHistory}
|
|
20
|
-
}
|
|
12
|
+
const buildSqlCountTemplate = ({ importLines, dbType, queries }) => `
|
|
13
|
+
${importLines}
|
|
14
|
+
export const getCountHistory = async (db: ${dbType}, uid: number) => {
|
|
15
|
+
${queries.selectHistory}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const createCountHistory = async (db: ${dbType}, count: number) => {
|
|
19
|
+
${queries.insertHistory}
|
|
20
|
+
}
|
|
21
21
|
`;
|
|
22
22
|
const drizzleQueryOperations = {
|
|
23
|
-
insertHistory: `const [newHistory] = await db.insert(schema.countHistory).values({ count }).returning()
|
|
23
|
+
insertHistory: `const [newHistory] = await db.insert(schema.countHistory).values({ count }).returning()
|
|
24
24
|
return newHistory`,
|
|
25
|
-
insertUser: `const [newUser] = await db
|
|
26
|
-
.insert(schema.users)
|
|
27
|
-
.values(newUserData)
|
|
28
|
-
.returning();
|
|
29
|
-
if (!newUser) throw new Error('Failed to create user');
|
|
30
|
-
return newUser;
|
|
25
|
+
insertUser: `const [newUser] = await db
|
|
26
|
+
.insert(schema.users)
|
|
27
|
+
.values(newUserData)
|
|
28
|
+
.returning();
|
|
29
|
+
if (!newUser) throw new Error('Failed to create user');
|
|
30
|
+
return newUser;
|
|
31
31
|
`,
|
|
32
|
-
selectHistory: `const [history] = await db.select().from(schema.countHistory).where(eq(schema.countHistory.uid, uid)).execute()
|
|
32
|
+
selectHistory: `const [history] = await db.select().from(schema.countHistory).where(eq(schema.countHistory.uid, uid)).execute()
|
|
33
33
|
return history`,
|
|
34
|
-
selectUser: `const [user] = await db
|
|
35
|
-
.select()
|
|
36
|
-
.from(schema.users)
|
|
37
|
-
.where(eq(schema.users.auth_sub, authSub))
|
|
38
|
-
.execute();
|
|
34
|
+
selectUser: `const [user] = await db
|
|
35
|
+
.select()
|
|
36
|
+
.from(schema.users)
|
|
37
|
+
.where(eq(schema.users.auth_sub, authSub))
|
|
38
|
+
.execute();
|
|
39
39
|
return user;`
|
|
40
40
|
};
|
|
41
41
|
const libsqlQueryOperations = {
|
|
42
|
-
insertHistory: `const { rows } = await db.execute({ sql: 'INSERT INTO count_history (count) VALUES (?) RETURNING *', args: [count] })
|
|
42
|
+
insertHistory: `const { rows } = await db.execute({ sql: 'INSERT INTO count_history (count) VALUES (?) RETURNING *', args: [count] })
|
|
43
43
|
return rows[0]`,
|
|
44
|
-
insertUser: `const { rows } = await db.execute({ sql: 'INSERT INTO users (auth_sub, metadata) VALUES (?, ?) RETURNING *', args: [authSub, JSON.stringify(userIdentity)] })
|
|
45
|
-
const newUser = rows[0]
|
|
46
|
-
if (!newUser) throw new Error('Failed to create user')
|
|
44
|
+
insertUser: `const { rows } = await db.execute({ sql: 'INSERT INTO users (auth_sub, metadata) VALUES (?, ?) RETURNING *', args: [authSub, JSON.stringify(userIdentity)] })
|
|
45
|
+
const newUser = rows[0]
|
|
46
|
+
if (!newUser) throw new Error('Failed to create user')
|
|
47
47
|
return newUser`,
|
|
48
|
-
selectHistory: `const { rows } = await db.execute({ sql: 'SELECT * FROM count_history WHERE uid = ? LIMIT 1', args: [uid] })
|
|
48
|
+
selectHistory: `const { rows } = await db.execute({ sql: 'SELECT * FROM count_history WHERE uid = ? LIMIT 1', args: [uid] })
|
|
49
49
|
return rows[0] ?? null`,
|
|
50
|
-
selectUser: `const { rows } = await db.execute({ sql: 'SELECT * FROM users WHERE auth_sub = ? LIMIT 1', args: [authSub] })
|
|
50
|
+
selectUser: `const { rows } = await db.execute({ sql: 'SELECT * FROM users WHERE auth_sub = ? LIMIT 1', args: [authSub] })
|
|
51
51
|
return rows[0] ?? null`
|
|
52
52
|
};
|
|
53
53
|
const bunSqliteQueryOperations = {
|
|
54
|
-
insertHistory: `db.run('INSERT INTO count_history (count) VALUES (?)', [count])
|
|
55
|
-
const statement = db.query('SELECT * FROM count_history ORDER BY rowid DESC LIMIT 1')
|
|
56
|
-
const [newHistory] = statement.all()
|
|
54
|
+
insertHistory: `db.run('INSERT INTO count_history (count) VALUES (?)', [count])
|
|
55
|
+
const statement = db.query('SELECT * FROM count_history ORDER BY rowid DESC LIMIT 1')
|
|
56
|
+
const [newHistory] = statement.all()
|
|
57
57
|
return newHistory`,
|
|
58
|
-
insertUser: `db.run('INSERT INTO users (auth_sub, metadata) VALUES (?, ?)', [authSub, JSON.stringify(userIdentity)])
|
|
59
|
-
const statement = db.query('SELECT * FROM users WHERE auth_sub = ? LIMIT 1')
|
|
60
|
-
const [newUser] = statement.all(authSub)
|
|
61
|
-
if (!newUser) throw new Error('Failed to create user')
|
|
58
|
+
insertUser: `db.run('INSERT INTO users (auth_sub, metadata) VALUES (?, ?)', [authSub, JSON.stringify(userIdentity)])
|
|
59
|
+
const statement = db.query('SELECT * FROM users WHERE auth_sub = ? LIMIT 1')
|
|
60
|
+
const [newUser] = statement.all(authSub)
|
|
61
|
+
if (!newUser) throw new Error('Failed to create user')
|
|
62
62
|
return newUser`,
|
|
63
|
-
selectHistory: `const statement = db.query('SELECT * FROM count_history WHERE uid = ? LIMIT 1')
|
|
64
|
-
const [history] = statement.all(uid)
|
|
63
|
+
selectHistory: `const statement = db.query('SELECT * FROM count_history WHERE uid = ? LIMIT 1')
|
|
64
|
+
const [history] = statement.all(uid)
|
|
65
65
|
return history ?? null`,
|
|
66
|
-
selectUser: `const statement = db.query('SELECT * FROM users WHERE auth_sub = ? LIMIT 1')
|
|
67
|
-
const [user] = statement.all(authSub)
|
|
66
|
+
selectUser: `const statement = db.query('SELECT * FROM users WHERE auth_sub = ? LIMIT 1')
|
|
67
|
+
const [user] = statement.all(authSub)
|
|
68
68
|
return user ?? null`
|
|
69
69
|
};
|
|
70
70
|
const postgresQueryOperations = {
|
|
71
|
-
insertHistory: `const { rows } = await db.query(
|
|
72
|
-
'INSERT INTO count_history (count) VALUES ($1) RETURNING *',
|
|
73
|
-
[count]
|
|
74
|
-
)
|
|
71
|
+
insertHistory: `const { rows } = await db.query(
|
|
72
|
+
'INSERT INTO count_history (count) VALUES ($1) RETURNING *',
|
|
73
|
+
[count]
|
|
74
|
+
)
|
|
75
75
|
return rows[0]`,
|
|
76
|
-
insertUser: `const { rows } = await db.query(
|
|
77
|
-
'INSERT INTO users (auth_sub, metadata) VALUES ($1, $2) RETURNING *',
|
|
78
|
-
[authSub, userIdentity]
|
|
79
|
-
)
|
|
80
|
-
const newUser = rows[0]
|
|
81
|
-
if (!newUser) throw new Error('Failed to create user')
|
|
76
|
+
insertUser: `const { rows } = await db.query(
|
|
77
|
+
'INSERT INTO users (auth_sub, metadata) VALUES ($1, $2) RETURNING *',
|
|
78
|
+
[authSub, userIdentity]
|
|
79
|
+
)
|
|
80
|
+
const newUser = rows[0]
|
|
81
|
+
if (!newUser) throw new Error('Failed to create user')
|
|
82
82
|
return newUser`,
|
|
83
|
-
selectHistory: `const { rows } = await db.query(
|
|
84
|
-
'SELECT * FROM count_history WHERE uid = $1 LIMIT 1',
|
|
85
|
-
[uid]
|
|
86
|
-
)
|
|
83
|
+
selectHistory: `const { rows } = await db.query(
|
|
84
|
+
'SELECT * FROM count_history WHERE uid = $1 LIMIT 1',
|
|
85
|
+
[uid]
|
|
86
|
+
)
|
|
87
87
|
return rows[0] ?? null`,
|
|
88
|
-
selectUser: `const { rows } = await db.query(
|
|
89
|
-
'SELECT * FROM users WHERE auth_sub = $1 LIMIT 1',
|
|
90
|
-
[authSub]
|
|
91
|
-
)
|
|
88
|
+
selectUser: `const { rows } = await db.query(
|
|
89
|
+
'SELECT * FROM users WHERE auth_sub = $1 LIMIT 1',
|
|
90
|
+
[authSub]
|
|
91
|
+
)
|
|
92
92
|
return rows[0] ?? null`
|
|
93
93
|
};
|
|
94
94
|
const postgresSqlQueryOperations = {
|
|
95
|
-
insertHistory: `const [newHistory] = await db\`
|
|
96
|
-
INSERT INTO count_history (count)
|
|
97
|
-
VALUES (\${count})
|
|
98
|
-
RETURNING *
|
|
99
|
-
\`
|
|
95
|
+
insertHistory: `const [newHistory] = await db\`
|
|
96
|
+
INSERT INTO count_history (count)
|
|
97
|
+
VALUES (\${count})
|
|
98
|
+
RETURNING *
|
|
99
|
+
\`
|
|
100
100
|
return newHistory`,
|
|
101
|
-
insertUser: `const [newUser] = await db\`
|
|
102
|
-
INSERT INTO users (auth_sub, metadata)
|
|
103
|
-
VALUES (\${authSub}, \${userIdentity})
|
|
104
|
-
RETURNING *
|
|
105
|
-
\`
|
|
106
|
-
if (!newUser) throw new Error('Failed to create user')
|
|
101
|
+
insertUser: `const [newUser] = await db\`
|
|
102
|
+
INSERT INTO users (auth_sub, metadata)
|
|
103
|
+
VALUES (\${authSub}, \${userIdentity})
|
|
104
|
+
RETURNING *
|
|
105
|
+
\`
|
|
106
|
+
if (!newUser) throw new Error('Failed to create user')
|
|
107
107
|
return newUser`,
|
|
108
|
-
selectHistory: `const [history] = await db\`
|
|
109
|
-
SELECT * FROM count_history
|
|
110
|
-
WHERE uid = \${uid}
|
|
111
|
-
LIMIT 1
|
|
112
|
-
\`
|
|
108
|
+
selectHistory: `const [history] = await db\`
|
|
109
|
+
SELECT * FROM count_history
|
|
110
|
+
WHERE uid = \${uid}
|
|
111
|
+
LIMIT 1
|
|
112
|
+
\`
|
|
113
113
|
return history ?? null`,
|
|
114
|
-
selectUser: `const [user] = await db\`
|
|
115
|
-
SELECT * FROM users
|
|
116
|
-
WHERE auth_sub = \${authSub}
|
|
117
|
-
LIMIT 1
|
|
118
|
-
\`
|
|
114
|
+
selectUser: `const [user] = await db\`
|
|
115
|
+
SELECT * FROM users
|
|
116
|
+
WHERE auth_sub = \${authSub}
|
|
117
|
+
LIMIT 1
|
|
118
|
+
\`
|
|
119
119
|
return user ?? null`
|
|
120
120
|
};
|
|
121
121
|
const mongodbQueryOperations = {
|
|
122
|
-
insertHistory: `const { insertedId } = await db.collection('count_history').insertOne({ count })
|
|
123
|
-
const newHistory = await db.collection('count_history').findOne({ _id: insertedId })
|
|
122
|
+
insertHistory: `const { insertedId } = await db.collection('count_history').insertOne({ count })
|
|
123
|
+
const newHistory = await db.collection('count_history').findOne({ _id: insertedId })
|
|
124
124
|
return newHistory`,
|
|
125
|
-
insertUser: `const { insertedId } = await db.collection('users').insertOne({ auth_sub: authSub, metadata: userIdentity })
|
|
126
|
-
const newUser = await db.collection('users').findOne({ _id: insertedId })
|
|
127
|
-
if (!newUser) throw new Error('Failed to create user')
|
|
125
|
+
insertUser: `const { insertedId } = await db.collection('users').insertOne({ auth_sub: authSub, metadata: userIdentity })
|
|
126
|
+
const newUser = await db.collection('users').findOne({ _id: insertedId })
|
|
127
|
+
if (!newUser) throw new Error('Failed to create user')
|
|
128
128
|
return newUser`,
|
|
129
|
-
selectHistory: `const history = await db.collection('count_history').findOne({ uid })
|
|
129
|
+
selectHistory: `const history = await db.collection('count_history').findOne({ uid })
|
|
130
130
|
return history ?? null`,
|
|
131
|
-
selectUser: `const user = await db.collection('users').findOne({ auth_sub: authSub })
|
|
131
|
+
selectUser: `const user = await db.collection('users').findOne({ auth_sub: authSub })
|
|
132
132
|
return user ?? null`
|
|
133
133
|
};
|
|
134
134
|
const gelClientQueryOperations = {
|
|
135
|
-
insertHistory: `const newHistory = await db.queryRequiredSingle(
|
|
136
|
-
'select (insert count_history { count := <int16>$count }) { uid, count, created_at }',
|
|
137
|
-
{ count }
|
|
138
|
-
)
|
|
135
|
+
insertHistory: `const newHistory = await db.queryRequiredSingle(
|
|
136
|
+
'select (insert count_history { count := <int16>$count }) { uid, count, created_at }',
|
|
137
|
+
{ count }
|
|
138
|
+
)
|
|
139
139
|
return newHistory`,
|
|
140
|
-
insertUser: `const newUser = await db.queryRequiredSingle(
|
|
141
|
-
'select (insert users { auth_sub := <str>$authSub, metadata := <json>$metadata }) { auth_sub, created_at, metadata }',
|
|
142
|
-
{ authSub, metadata: userIdentity }
|
|
143
|
-
)
|
|
140
|
+
insertUser: `const newUser = await db.queryRequiredSingle(
|
|
141
|
+
'select (insert users { auth_sub := <str>$authSub, metadata := <json>$metadata }) { auth_sub, created_at, metadata }',
|
|
142
|
+
{ authSub, metadata: userIdentity }
|
|
143
|
+
)
|
|
144
144
|
return newUser`,
|
|
145
|
-
selectHistory: `const history = await db.querySingle(
|
|
146
|
-
'select count_history { uid, count, created_at } filter .uid = <int64>$uid',
|
|
147
|
-
{ uid }
|
|
148
|
-
)
|
|
145
|
+
selectHistory: `const history = await db.querySingle(
|
|
146
|
+
'select count_history { uid, count, created_at } filter .uid = <int64>$uid',
|
|
147
|
+
{ uid }
|
|
148
|
+
)
|
|
149
149
|
return history ?? null`,
|
|
150
|
-
selectUser: `const user = await db.querySingle(
|
|
151
|
-
'select users { auth_sub, created_at, metadata } filter .auth_sub = <str>$authSub',
|
|
152
|
-
{ authSub }
|
|
153
|
-
)
|
|
150
|
+
selectUser: `const user = await db.querySingle(
|
|
151
|
+
'select users { auth_sub, created_at, metadata } filter .auth_sub = <str>$authSub',
|
|
152
|
+
{ authSub }
|
|
153
|
+
)
|
|
154
154
|
return user ?? null`
|
|
155
155
|
};
|
|
156
156
|
const singlestoreSqlQueryOperations = {
|
|
157
|
-
insertHistory: `await db.query('INSERT INTO count_history (count) VALUES (?)', [count])
|
|
158
|
-
const [rows] = await db.query<RowDataPacket[]>('SELECT * FROM count_history ORDER BY uid DESC LIMIT 1')
|
|
157
|
+
insertHistory: `await db.query('INSERT INTO count_history (count) VALUES (?)', [count])
|
|
158
|
+
const [rows] = await db.query<RowDataPacket[]>('SELECT * FROM count_history ORDER BY uid DESC LIMIT 1')
|
|
159
159
|
return rows[0]`,
|
|
160
|
-
insertUser: `await db.query('INSERT INTO users (auth_sub, metadata) VALUES (?, ?)', [authSub, JSON.stringify(userIdentity)])
|
|
161
|
-
const [rows] = await db.query<RowDataPacket[]>('SELECT * FROM users WHERE auth_sub = ? LIMIT 1', [authSub])
|
|
162
|
-
const newUser = rows[0]
|
|
163
|
-
if (!newUser) throw new Error('Failed to create user')
|
|
160
|
+
insertUser: `await db.query('INSERT INTO users (auth_sub, metadata) VALUES (?, ?)', [authSub, JSON.stringify(userIdentity)])
|
|
161
|
+
const [rows] = await db.query<RowDataPacket[]>('SELECT * FROM users WHERE auth_sub = ? LIMIT 1', [authSub])
|
|
162
|
+
const newUser = rows[0]
|
|
163
|
+
if (!newUser) throw new Error('Failed to create user')
|
|
164
164
|
return newUser`,
|
|
165
|
-
selectHistory: `const [rows] = await db.query<RowDataPacket[]>('SELECT * FROM count_history WHERE uid = ? LIMIT 1', [uid])
|
|
165
|
+
selectHistory: `const [rows] = await db.query<RowDataPacket[]>('SELECT * FROM count_history WHERE uid = ? LIMIT 1', [uid])
|
|
166
166
|
return rows[0] ?? null`,
|
|
167
|
-
selectUser: `const [rows] = await db.query<RowDataPacket[]>('SELECT * FROM users WHERE auth_sub = ? LIMIT 1', [authSub])
|
|
167
|
+
selectUser: `const [rows] = await db.query<RowDataPacket[]>('SELECT * FROM users WHERE auth_sub = ? LIMIT 1', [authSub])
|
|
168
168
|
return rows[0] ?? null`
|
|
169
169
|
};
|
|
170
170
|
const mssqlSqlQueryOperations = {
|
|
171
|
-
insertHistory: `await db.request().input('count', count).query('INSERT INTO count_history (count) VALUES (@count)')
|
|
172
|
-
const result = await db.request().query('SELECT TOP 1 * FROM count_history ORDER BY uid DESC')
|
|
171
|
+
insertHistory: `await db.request().input('count', count).query('INSERT INTO count_history (count) VALUES (@count)')
|
|
172
|
+
const result = await db.request().query('SELECT TOP 1 * FROM count_history ORDER BY uid DESC')
|
|
173
173
|
return result.recordset[0]`,
|
|
174
|
-
insertUser: `await db.request().input('authSub', authSub).input('metadata', JSON.stringify(userIdentity)).query('INSERT INTO users (auth_sub, metadata) VALUES (@authSub, @metadata)')
|
|
175
|
-
const result = await db.request().input('authSub', authSub).query('SELECT TOP 1 * FROM users WHERE auth_sub = @authSub')
|
|
176
|
-
const newUser = result.recordset[0]
|
|
177
|
-
if (!newUser) throw new Error('Failed to create user')
|
|
174
|
+
insertUser: `await db.request().input('authSub', authSub).input('metadata', JSON.stringify(userIdentity)).query('INSERT INTO users (auth_sub, metadata) VALUES (@authSub, @metadata)')
|
|
175
|
+
const result = await db.request().input('authSub', authSub).query('SELECT TOP 1 * FROM users WHERE auth_sub = @authSub')
|
|
176
|
+
const newUser = result.recordset[0]
|
|
177
|
+
if (!newUser) throw new Error('Failed to create user')
|
|
178
178
|
return newUser`,
|
|
179
|
-
selectHistory: `const result = await db.request().input('uid', uid).query('SELECT TOP 1 * FROM count_history WHERE uid = @uid')
|
|
179
|
+
selectHistory: `const result = await db.request().input('uid', uid).query('SELECT TOP 1 * FROM count_history WHERE uid = @uid')
|
|
180
180
|
return result.recordset[0] ?? null`,
|
|
181
|
-
selectUser: `const result = await db.request().input('authSub', authSub).query('SELECT TOP 1 * FROM users WHERE auth_sub = @authSub')
|
|
181
|
+
selectUser: `const result = await db.request().input('authSub', authSub).query('SELECT TOP 1 * FROM users WHERE auth_sub = @authSub')
|
|
182
182
|
return result.recordset[0] ?? null`
|
|
183
183
|
};
|
|
184
184
|
const mysqlSqlQueryOperations = {
|
|
185
|
-
insertHistory: `
|
|
186
|
-
const result = await db\`
|
|
187
|
-
INSERT INTO count_history (count)
|
|
188
|
-
VALUES (\${count})
|
|
189
|
-
\`;
|
|
190
|
-
|
|
191
|
-
const insertId = result.lastInsertRowid;
|
|
192
|
-
|
|
193
|
-
const [row] = await db\`
|
|
194
|
-
SELECT *
|
|
195
|
-
FROM count_history
|
|
196
|
-
WHERE uid = \${insertId}
|
|
197
|
-
LIMIT 1
|
|
198
|
-
\`;
|
|
199
|
-
|
|
200
|
-
if (!row) throw new Error("Could not retrieve the newly-inserted history");
|
|
201
|
-
return row;
|
|
185
|
+
insertHistory: `
|
|
186
|
+
const result = await db\`
|
|
187
|
+
INSERT INTO count_history (count)
|
|
188
|
+
VALUES (\${count})
|
|
189
|
+
\`;
|
|
190
|
+
|
|
191
|
+
const insertId = result.lastInsertRowid;
|
|
192
|
+
|
|
193
|
+
const [row] = await db\`
|
|
194
|
+
SELECT *
|
|
195
|
+
FROM count_history
|
|
196
|
+
WHERE uid = \${insertId}
|
|
197
|
+
LIMIT 1
|
|
198
|
+
\`;
|
|
199
|
+
|
|
200
|
+
if (!row) throw new Error("Could not retrieve the newly-inserted history");
|
|
201
|
+
return row;
|
|
202
202
|
`,
|
|
203
|
-
insertUser: `
|
|
204
|
-
const result = await db\`
|
|
205
|
-
INSERT INTO users (auth_sub, metadata)
|
|
206
|
-
VALUES (\${authSub}, \${JSON.stringify(userIdentity)})
|
|
207
|
-
\`;
|
|
208
|
-
|
|
209
|
-
const [row] = await db\`
|
|
210
|
-
SELECT *
|
|
211
|
-
FROM users
|
|
212
|
-
WHERE auth_sub = \${authSub}
|
|
213
|
-
LIMIT 1
|
|
214
|
-
\`;
|
|
215
|
-
|
|
216
|
-
if (!row) throw new Error("Failed to create user");
|
|
217
|
-
return row;
|
|
203
|
+
insertUser: `
|
|
204
|
+
const result = await db\`
|
|
205
|
+
INSERT INTO users (auth_sub, metadata)
|
|
206
|
+
VALUES (\${authSub}, \${JSON.stringify(userIdentity)})
|
|
207
|
+
\`;
|
|
208
|
+
|
|
209
|
+
const [row] = await db\`
|
|
210
|
+
SELECT *
|
|
211
|
+
FROM users
|
|
212
|
+
WHERE auth_sub = \${authSub}
|
|
213
|
+
LIMIT 1
|
|
214
|
+
\`;
|
|
215
|
+
|
|
216
|
+
if (!row) throw new Error("Failed to create user");
|
|
217
|
+
return row;
|
|
218
218
|
`,
|
|
219
|
-
selectHistory: `
|
|
220
|
-
const [row] = await db\`
|
|
221
|
-
SELECT *
|
|
222
|
-
FROM count_history
|
|
223
|
-
WHERE uid = \${uid}
|
|
224
|
-
LIMIT 1
|
|
225
|
-
\`;
|
|
226
|
-
|
|
227
|
-
return row ?? null;
|
|
219
|
+
selectHistory: `
|
|
220
|
+
const [row] = await db\`
|
|
221
|
+
SELECT *
|
|
222
|
+
FROM count_history
|
|
223
|
+
WHERE uid = \${uid}
|
|
224
|
+
LIMIT 1
|
|
225
|
+
\`;
|
|
226
|
+
|
|
227
|
+
return row ?? null;
|
|
228
228
|
`,
|
|
229
|
-
selectUser: `
|
|
230
|
-
const [row] = await db\`
|
|
231
|
-
SELECT *
|
|
232
|
-
FROM users
|
|
233
|
-
WHERE auth_sub = \${authSub}
|
|
234
|
-
LIMIT 1
|
|
235
|
-
\`;
|
|
236
|
-
|
|
237
|
-
return row ?? null;
|
|
229
|
+
selectUser: `
|
|
230
|
+
const [row] = await db\`
|
|
231
|
+
SELECT *
|
|
232
|
+
FROM users
|
|
233
|
+
WHERE auth_sub = \${authSub}
|
|
234
|
+
LIMIT 1
|
|
235
|
+
\`;
|
|
236
|
+
|
|
237
|
+
return row ?? null;
|
|
238
238
|
`
|
|
239
239
|
};
|
|
240
240
|
const mysqlDrizzleQueryOperations = {
|
|
241
|
-
insertHistory: `const [row] = await db
|
|
242
|
-
.insert(schema.countHistory)
|
|
243
|
-
.values({ count })
|
|
244
|
-
.$returningId();
|
|
245
|
-
|
|
246
|
-
if (!row) throw new Error('insert failed: no uid returned');
|
|
247
|
-
const { uid } = row;
|
|
248
|
-
|
|
249
|
-
const [newHistory] = await db
|
|
250
|
-
.select()
|
|
251
|
-
.from(schema.countHistory)
|
|
252
|
-
.where(eq(schema.countHistory.uid, uid));
|
|
253
|
-
|
|
241
|
+
insertHistory: `const [row] = await db
|
|
242
|
+
.insert(schema.countHistory)
|
|
243
|
+
.values({ count })
|
|
244
|
+
.$returningId();
|
|
245
|
+
|
|
246
|
+
if (!row) throw new Error('insert failed: no uid returned');
|
|
247
|
+
const { uid } = row;
|
|
248
|
+
|
|
249
|
+
const [newHistory] = await db
|
|
250
|
+
.select()
|
|
251
|
+
.from(schema.countHistory)
|
|
252
|
+
.where(eq(schema.countHistory.uid, uid));
|
|
253
|
+
|
|
254
254
|
return newHistory;`,
|
|
255
|
-
insertUser: `const [row] = await db
|
|
256
|
-
.insert(schema.users)
|
|
257
|
-
.values({ auth_sub: authSub, metadata: userIdentity });
|
|
258
|
-
|
|
259
|
-
const [newUser] = await db
|
|
260
|
-
.select()
|
|
261
|
-
.from(schema.users)
|
|
262
|
-
.where(eq(schema.users.auth_sub, authSub));
|
|
263
|
-
|
|
264
|
-
if (!newUser) throw new Error('Failed to create user');
|
|
255
|
+
insertUser: `const [row] = await db
|
|
256
|
+
.insert(schema.users)
|
|
257
|
+
.values({ auth_sub: authSub, metadata: userIdentity });
|
|
258
|
+
|
|
259
|
+
const [newUser] = await db
|
|
260
|
+
.select()
|
|
261
|
+
.from(schema.users)
|
|
262
|
+
.where(eq(schema.users.auth_sub, authSub));
|
|
263
|
+
|
|
264
|
+
if (!newUser) throw new Error('Failed to create user');
|
|
265
265
|
return newUser;`,
|
|
266
266
|
selectHistory: drizzleQueryOperations.selectHistory,
|
|
267
267
|
selectUser: drizzleQueryOperations.selectUser
|
|
268
268
|
};
|
|
269
269
|
const mysqlPlanetScaleQueryOperations = {
|
|
270
|
-
insertHistory: `
|
|
271
|
-
const result = await db.execute(
|
|
272
|
-
\`INSERT INTO count_history (count) VALUES (?)\`,
|
|
273
|
-
[count]
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
const insertId = result.insertId;
|
|
277
|
-
if (!insertId) throw new Error("Could not insert count history");
|
|
278
|
-
|
|
279
|
-
const { rows } = await db.execute(
|
|
280
|
-
\`SELECT * FROM count_history WHERE uid = ? LIMIT 1\`,
|
|
281
|
-
[insertId]
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
const row = rows[0] ?? null;
|
|
285
|
-
if (!row) throw new Error("Could not retrieve the newly-inserted history");
|
|
286
|
-
|
|
287
|
-
return row;
|
|
270
|
+
insertHistory: `
|
|
271
|
+
const result = await db.execute(
|
|
272
|
+
\`INSERT INTO count_history (count) VALUES (?)\`,
|
|
273
|
+
[count]
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
const insertId = result.insertId;
|
|
277
|
+
if (!insertId) throw new Error("Could not insert count history");
|
|
278
|
+
|
|
279
|
+
const { rows } = await db.execute(
|
|
280
|
+
\`SELECT * FROM count_history WHERE uid = ? LIMIT 1\`,
|
|
281
|
+
[insertId]
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
const row = rows[0] ?? null;
|
|
285
|
+
if (!row) throw new Error("Could not retrieve the newly-inserted history");
|
|
286
|
+
|
|
287
|
+
return row;
|
|
288
288
|
`,
|
|
289
|
-
insertUser: `
|
|
290
|
-
const result = await db.execute(
|
|
291
|
-
\`INSERT INTO users (auth_sub, metadata) VALUES (?, ?)\`,
|
|
292
|
-
[authSub, JSON.stringify(userIdentity)]
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
const { rows } = await db.execute(
|
|
296
|
-
\`SELECT * FROM users WHERE auth_sub = ? LIMIT 1\`,
|
|
297
|
-
[authSub]
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
const row = rows[0] ?? null;
|
|
301
|
-
if (!row) throw new Error("Failed to create user");
|
|
302
|
-
|
|
303
|
-
return row;
|
|
289
|
+
insertUser: `
|
|
290
|
+
const result = await db.execute(
|
|
291
|
+
\`INSERT INTO users (auth_sub, metadata) VALUES (?, ?)\`,
|
|
292
|
+
[authSub, JSON.stringify(userIdentity)]
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
const { rows } = await db.execute(
|
|
296
|
+
\`SELECT * FROM users WHERE auth_sub = ? LIMIT 1\`,
|
|
297
|
+
[authSub]
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
const row = rows[0] ?? null;
|
|
301
|
+
if (!row) throw new Error("Failed to create user");
|
|
302
|
+
|
|
303
|
+
return row;
|
|
304
304
|
`,
|
|
305
|
-
selectHistory: `
|
|
306
|
-
const { rows } = await db.execute(
|
|
307
|
-
\`SELECT * FROM count_history WHERE uid = ? LIMIT 1\`,
|
|
308
|
-
[uid]
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
return rows[0] ?? null;
|
|
305
|
+
selectHistory: `
|
|
306
|
+
const { rows } = await db.execute(
|
|
307
|
+
\`SELECT * FROM count_history WHERE uid = ? LIMIT 1\`,
|
|
308
|
+
[uid]
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
return rows[0] ?? null;
|
|
312
312
|
`,
|
|
313
|
-
selectUser: `
|
|
314
|
-
const { rows } = await db.execute(
|
|
315
|
-
\`SELECT * FROM users WHERE auth_sub = ? LIMIT 1\`,
|
|
316
|
-
[authSub]
|
|
317
|
-
);
|
|
318
|
-
|
|
319
|
-
return rows[0] ?? null;
|
|
313
|
+
selectUser: `
|
|
314
|
+
const { rows } = await db.execute(
|
|
315
|
+
\`SELECT * FROM users WHERE auth_sub = ? LIMIT 1\`,
|
|
316
|
+
[authSub]
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
return rows[0] ?? null;
|
|
320
320
|
`
|
|
321
321
|
};
|
|
322
322
|
const driverConfigurations = {
|
|
@@ -327,8 +327,8 @@ const driverConfigurations = {
|
|
|
327
327
|
},
|
|
328
328
|
'gel:drizzle:local': {
|
|
329
329
|
dbType: 'GelJsDatabase<SchemaType>',
|
|
330
|
-
importLines: `import { eq } from 'drizzle-orm'
|
|
331
|
-
import { schema } from '../../../db/schema'
|
|
330
|
+
importLines: `import { eq } from 'drizzle-orm'
|
|
331
|
+
import { schema } from '../../../db/schema'
|
|
332
332
|
`,
|
|
333
333
|
queries: drizzleQueryOperations
|
|
334
334
|
},
|
|
@@ -339,7 +339,7 @@ import { schema } from '../../../db/schema'
|
|
|
339
339
|
},
|
|
340
340
|
'mariadb:drizzle:local': {
|
|
341
341
|
dbType: 'MySql2Database<SchemaType>',
|
|
342
|
-
importLines: `import { eq } from 'drizzle-orm'
|
|
342
|
+
importLines: `import { eq } from 'drizzle-orm'
|
|
343
343
|
import { schema } from '../../../db/schema'`,
|
|
344
344
|
queries: mysqlDrizzleQueryOperations
|
|
345
345
|
},
|
|
@@ -360,13 +360,13 @@ import { schema } from '../../../db/schema'`,
|
|
|
360
360
|
},
|
|
361
361
|
'mysql:drizzle:local': {
|
|
362
362
|
dbType: 'MySql2Database<SchemaType>',
|
|
363
|
-
importLines: `import { eq } from 'drizzle-orm'
|
|
363
|
+
importLines: `import { eq } from 'drizzle-orm'
|
|
364
364
|
import { schema } from '../../../db/schema'`,
|
|
365
365
|
queries: mysqlDrizzleQueryOperations
|
|
366
366
|
},
|
|
367
367
|
'mysql:drizzle:planetscale': {
|
|
368
368
|
dbType: 'PlanetScaleDatabase<SchemaType>',
|
|
369
|
-
importLines: `import { eq } from 'drizzle-orm'
|
|
369
|
+
importLines: `import { eq } from 'drizzle-orm'
|
|
370
370
|
import { schema } from '../../../db/schema'`,
|
|
371
371
|
queries: mysqlDrizzleQueryOperations
|
|
372
372
|
},
|
|
@@ -382,19 +382,19 @@ import { schema } from '../../../db/schema'`,
|
|
|
382
382
|
},
|
|
383
383
|
'postgresql:drizzle:local': {
|
|
384
384
|
dbType: 'BunSQLDatabase<SchemaType>',
|
|
385
|
-
importLines: `import { eq } from 'drizzle-orm'
|
|
385
|
+
importLines: `import { eq } from 'drizzle-orm'
|
|
386
386
|
import { schema } from '../../../db/schema'`,
|
|
387
387
|
queries: drizzleQueryOperations
|
|
388
388
|
},
|
|
389
389
|
'postgresql:drizzle:neon': {
|
|
390
390
|
dbType: 'NeonDatabase<SchemaType>',
|
|
391
|
-
importLines: `import { eq } from 'drizzle-orm'
|
|
391
|
+
importLines: `import { eq } from 'drizzle-orm'
|
|
392
392
|
import { schema } from '../../../db/schema'`,
|
|
393
393
|
queries: drizzleQueryOperations
|
|
394
394
|
},
|
|
395
395
|
'postgresql:drizzle:planetscale': {
|
|
396
396
|
dbType: 'NodePgDatabase<SchemaType>',
|
|
397
|
-
importLines: `import { eq } from 'drizzle-orm'
|
|
397
|
+
importLines: `import { eq } from 'drizzle-orm'
|
|
398
398
|
import { schema } from '../../../db/schema'`,
|
|
399
399
|
queries: drizzleQueryOperations
|
|
400
400
|
},
|
|
@@ -415,25 +415,25 @@ import { schema } from '../../../db/schema'`,
|
|
|
415
415
|
},
|
|
416
416
|
'singlestore:drizzle:local': {
|
|
417
417
|
dbType: 'SingleStoreDriverDatabase<SchemaType>',
|
|
418
|
-
importLines: `import { eq } from 'drizzle-orm'
|
|
418
|
+
importLines: `import { eq } from 'drizzle-orm'
|
|
419
419
|
import { schema } from '../../../db/schema'`,
|
|
420
420
|
queries: mysqlDrizzleQueryOperations
|
|
421
421
|
},
|
|
422
422
|
'singlestore:sql:local': {
|
|
423
423
|
dbType: 'Pool',
|
|
424
|
-
importLines: `import { RowDataPacket } from 'mysql2/promise'
|
|
424
|
+
importLines: `import { RowDataPacket } from 'mysql2/promise'
|
|
425
425
|
`,
|
|
426
426
|
queries: singlestoreSqlQueryOperations
|
|
427
427
|
},
|
|
428
428
|
'sqlite:drizzle:local': {
|
|
429
429
|
dbType: 'BunSQLiteDatabase<SchemaType>',
|
|
430
|
-
importLines: `import { eq } from 'drizzle-orm'
|
|
430
|
+
importLines: `import { eq } from 'drizzle-orm'
|
|
431
431
|
import { schema } from '../../../db/schema'`,
|
|
432
432
|
queries: drizzleQueryOperations
|
|
433
433
|
},
|
|
434
434
|
'sqlite:drizzle:turso': {
|
|
435
435
|
dbType: 'LibSQLDatabase<SchemaType>',
|
|
436
|
-
importLines: `import { eq } from 'drizzle-orm'
|
|
436
|
+
importLines: `import { eq } from 'drizzle-orm'
|
|
437
437
|
import { schema } from '../../../db/schema'`,
|
|
438
438
|
queries: drizzleQueryOperations
|
|
439
439
|
},
|
|
@@ -22,7 +22,7 @@ export const scaffoldDocker = async ({ databaseEngine, projectDatabaseDirectory,
|
|
|
22
22
|
? userTables[databaseEngine]
|
|
23
23
|
: countHistoryTables[databaseEngine];
|
|
24
24
|
await $ `bun db:up`.cwd(projectName);
|
|
25
|
-
await $ `docker compose -p ${databaseEngine} -f db/docker-compose.db.yml exec -T db \
|
|
25
|
+
await $ `docker compose -p ${databaseEngine} -f db/docker-compose.db.yml exec -T db \
|
|
26
26
|
bash -lc '${wait} && ${cli} "${dbCommand}"'`.cwd(projectName);
|
|
27
27
|
await $ `bun db:down`.cwd(projectName);
|
|
28
28
|
}
|